Kotlin - Collections Fundamentals
Which of the following is the correct syntax to create an array of size 5 with all elements initialized to zero in Kotlin?
Array(size) { init } creates an array of given size, initializing each element with the lambda result.val arr = Array(5) { 0 } correctly uses Array(5) { 0 } to create an array of 5 zeros. val arr = Array(0, 0, 0, 0, 0) is invalid syntax. val arr = Array(5, 0) is invalid syntax. val arr = IntArray(5, 0) is invalid because IntArray constructor takes only size or size with init lambda, not two parameters.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions