If the specified key is not already associated
with a value, associate it with the given value.
This is equivalent to
if (!map.containsKey(key))
return map.put(key, value);
else
return map.get(key);
except that the action is performed atomically.
Returns:
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.)
Parameters:
-
key - key with which the specified value is to be associated
-
value - value to be associated with the specified key
Throws:
-
UnsupportedOperationException - if the
put operation
is not supported by this map
-
ClassCastException - if the class of the specified key or value
prevents it from being stored in this map
-
NullPointerException - if the specified key or value is null,
and this map does not permit null keys or values
-
IllegalArgumentException - if some property of the specified key
or value prevents it from being stored in this map