Kotlin HashMap getOrPut()
Syntax & Examples


Syntax of HashMap.getOrPut()

The syntax of HashMap.getOrPut() extension function is:

fun <K, V> MutableMap<K, V>.getOrPut( key: K, defaultValue: () -> V ): V

This getOrPut() extension function of HashMap returns the value for the given key if the value is present and not null. Otherwise, calls the defaultValue function, puts its result into the map under the given key and returns the call result.