Kotlin Sets and Maps
A set holds unique values and a map holds key value pairs. mapOf is read only and mutableMapOf can change.
Example
val set = setOf(1, 2, 2, 3)
val ages = mutableMapOf("Ada" to 21, "Tunde" to 30)
ages["Zed"] = 25
println("${set.size} ${ages["Ada"]} ${ages.keys}")
for ((k, v) in ages) println("$k=$v")Exercise
Build a pair.
"a" 1
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.