Maps
mapOf pairs keys with values using to. Use get, getOrDefault, keys and values.
Example
val m = mapOf("a" to 1, "b" to 2)
println(m["a"])
println(m.getOrDefault("z", 0))
println(m.keys)
for ((k, v) in m) print("$k=$v ")
println()
val mm = mutableMapOf("x" to 1)
mm["y"] = 2
println(mm)Exercise
Pair a key.
"a" 1
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.