Java Reference
In-Depth Information
public int
hashCode()
Returns the hash code value for the calling object. The hash code of a map is defi ned to be the
sum of the
hashCodes
of each entry in the map's
entrySet
view.
public boolean
isEmpty()
Returns
true
if the calling object is empty; otherwise returns
false
.
public int
size()
Returns the number of (key, value) mappings in the calling object.
public
Collection<V> values()
Returns a collection view consisting of all values in the map. Changes to the map are refl ected in
the collection and vice-versa.
OPTIONAL METHODS
The following methods are optional, which means they still must be implemented, but the
implementation can simply throw an
UnsupportedOperationException
if, for some reason,
you do not want to give them a “real” implementation. An
UnsupportedOperationException
is a
RunTimeException
and so is not required to be caught or declared in a
throws
clause.
public
V put(K key, V value)
(Optional)
Associates
key
to
value
in the map. If
key
was associated with an existing value, then the old
value is overwritten and returned. Otherwise
null
is returned.
Throws:
ClassCastException
if the type of
key
or
value
is incompatible with the type for this
map (optional).
NullPointerException
if the key or value is
null
and this map does not permit
null
keys
or values (optional).
IllegalArgumentException
if some aspect of the key or value prevents it from being stored
in this map (optional).
UnsupportedOperationException
if the
put
operation is not supported by this
map (optional).
public void
putAll(Map<? extends K,? extends V> mapToAdd)
(Optional)
Adds all mappings of
mapToAdd
into the calling object's map.
Throws:
ClassCastException
if any type of
key
or
value
of
mapToAdd
is incompatible with the
type for this map (optional).
NullPointerException
if
mapToAdd
is
null
or any key or value of
mapToAdd
is null and
this map does not permit null keys or values (optional).
IllegalArgumentException
if some aspect of the key or value from
mapToAdd
prevents it
from being stored in this map (optional).
UnsupportedOperationException
if the
putAll
operation is not supported by this
map (optional).