What is the output?
fun main() {
val m = mutableMapOf("a" to 2)
val b = m.getOrPut("b") { 9 }
println(b + (m["a"] ?: 0))
}
Try it in the online Kotlin Playground →
[spoiler title="Solution"]
Answer:
11
Explanation:
getOrPut returns the value for key ‘b’ if present, otherwise inserts and returns the default value (9). Since ‘b’ is missing, it’s added with value 9.
[/spoiler]