Complete the code to create an immutable list in Kotlin.
val numbers = listOf[1](1, 2, 3, 4, 5)
In Kotlin, listOf creates an immutable list by default.
Complete the code to try adding an element to an immutable list and see the error.
val fruits = listOf("Apple", "Banana") fruits.[1]("Cherry")
The add function is not available on immutable lists, so this code will cause an error.
Fix the error by choosing the correct mutable collection type to allow adding elements.
val fruits = [1]("Apple", "Banana") fruits.add("Cherry")
Using mutableListOf creates a list that can be changed, so add works.
Fill both blanks to create an immutable map and access a value safely.
val capitals = [1]("France" to "Paris", "Japan" to "Tokyo") val capital = capitals.[2]("France")
mapOf creates an immutable map, and get retrieves a value by key.
Fill all three blanks to filter an immutable list and create a new list with only even numbers.
val numbers = listOf(1, 2, 3, 4, 5, 6) val evens = numbers.[1] { it [2] 2 [3] 0 }
filter creates a new list with elements matching the condition. The condition checks if the number modulo 2 equals 0, meaning it's even.