setIfMissing method

V setIfMissing(
  1. K key,
  2. V value
)

Inserts a key-value pair into the map if the key does not already exist.

If the key exists, its associated value is returned; otherwise, the new value is inserted and then returned.

Implementation

V setIfMissing(K key, V value) {
  if (!containsKey(key)) {
    this[key] = value;
    return value;
  }
  return this[key] as V;
}