Complete the code to declare an immutable list in Kotlin.
val numbers: List<Int> = [1](1, 2, 3)
In Kotlin, listOf creates an immutable list, which means you cannot change its elements after creation.
Complete the code to add an element to a mutable list in Kotlin.
val numbers = mutableListOf(1, 2, 3) numbers.[1](4)
The add function adds an element to a mutable list in Kotlin.
Fix the error in the code by choosing the correct interface to declare a mutable list.
val numbers: [1]<Int> = mutableListOf(1, 2, 3)
To declare a mutable list interface in Kotlin, use MutableList. The List interface is read-only.
Fill both blanks to create an immutable map from a mutable map in Kotlin.
val mutableMap = mutableMapOf("a" to 1, "b" to 2) val immutableMap: [1]<String, Int> = mutableMap val readOnlyMap: [2]<String, Int> = immutableMap
Both immutableMap and readOnlyMap use the Map interface, which is read-only in Kotlin.
Fill all three blanks to filter a mutable list and create an immutable list in Kotlin.
val mutableList = mutableListOf(1, 2, 3, 4, 5) val filteredList: [1]<Int> = mutableList.[2] { it [3] 3 }
The filter function returns a new List (immutable) containing elements greater than 3.