Kotlin - Collections Fundamentals
You want to create an array of size 4 where each element is its index squared (0, 1, 4, 9). Which Kotlin code correctly does this?
Array(size) { index -> value } creates an array where each element is initialized by the lambda using the index.val arr = Array(4) { index -> index * index } uses explicit lambda parameter index and correctly computes index squared. val arr = arrayOf(4) { index -> index * index } is invalid because arrayOf does not take a size and lambda. val arr = intArrayOf(4) { index -> index * index } is invalid syntax for the intArrayOf factory function. val arr = Array(4) { -> it * it } has invalid lambda syntax where it is undefined.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions