KotlinMapgetOrElse

Returns the value for the given key, or the result of the defaultValue function.

Syntax

map.getOrElse(key) { default }

Example

Enter values below to update the example in real time.

val
map
mapOf
to
println
getOrElse
val map = mapOf("a" to 1, "b" to 2)
println(map.getOrElse("c") { 0 }) // 0