putIfAbsent

fun putIfAbsent(key: K, value: V): V?

If the specified key is not already associated with a value (or is mapped to null), associates it with the given value and returns null, else returns the current value.

Return

the previous value associated with the specified key, or null if there was no mapping for the key. (A null return can also indicate that the map previously associated null with the key)

Parameters

key

key with which the specified value is to be associated

value

value to be associated with the specified key

Throws

if the key cannot be compared

if key is null and nulls are not supported