putIfAbsent method

V? putIfAbsent(
  1. K key,
  2. V value
)

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, if the implementation supports null values.)

Implementation

V? putIfAbsent(K key, V value) => get(key) ?? put(key, value);