merge

fun merge(key: K, value: V, remappingFunction: (V, V) -> V?): V?

If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value. Otherwise, replaces the associated value with the results of the given remapping function, or removes if the result is null.

Throws

if the specified value or the result of the remapping function is null

if the remapping function modifies this map