Kotlin - Collections Fundamentals
Identify the error in this Kotlin code snippet:
val nums = listOf(1, 2, 3) nums.forEach(i -> println(i))
val nums = listOf(1, 2, 3) nums.forEach(i -> println(i))
{} for lambdas, not arrow notation like -> outside braces. The arrow is used inside the lambda to separate parameters from body.i -> println(i) directly after forEach without braces, which is invalid syntax. Correct form is nums.forEach { i -> println(i) }.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions