Kotlin - Collections Fundamentals
What is wrong with this Kotlin code and how can it be fixed?
val numbers = listOf(5, 10, 15) val result = numbers[4] ?: 0 println(result)
What is wrong with this Kotlin code and how can it be fixed?
val numbers = listOf(5, 10, 15) val result = numbers[4] ?: 0 println(result)
numbers[4] throws IndexOutOfBoundsException because index 4 is out of range.numbers.getOrNull(4) ?: 0 to safely get null if index is invalid, then default to 0.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions