replace

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

Replaces the entry for the specified key only if it is currently mapped to some 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 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


fun replace(key: K, oldValue: V, newValue: V): Boolean

Replaces the entry for the specified key only if currently mapped to the specified value.

Return

true if the value was replaced

Parameters

key

key with which the specified value is associated

oldValue

value expected to be associated with the specified key

newValue

value to be associated with the specified key

Throws

if the key cannot be compared

if key is null and nulls are not supported