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.
key | key with which the specified value is to be associated | |
value | value to be associated with the specified key |
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.)
UnsupportedOperationException | if the put operation
is not supported by this map
(optional) | |
ClassCastException | if the key or value is of an inappropriate type for this map (optional) | |
NullPointerException | if the specified key or value is null, and this map does not permit null keys or values (optional) | |
IllegalArgumentException | if some property of the specified key or value prevents it from being stored in this map (optional) |
@implSpec
The default implementation is equivalent to, for this
map:
V v = map.get(key);
if (v == null)
v = map.put(key, value);
return v;
The default implementation makes no guarantees about synchronization
or atomicity properties of this method. Any implementation providing
atomicity guarantees must override this method and document its
concurrency properties.
Diagram: Map Simple