java.lang.Object | |
↳ | java.util.AbstractMap<K, V> |
Known Direct Subclasses
ConcurrentHashMap<K, V>,
ConcurrentSkipListMap<K, V>,
EnumMap<K extends Enum<K>, V>,
HashMap<K, V>,
IdentityHashMap<K, V>,
TreeMap<K, V>,
WeakHashMap<K, V>
|
Known Indirect Subclasses
LinkedHashMap<K, V>
|
A base class for Map
implementations.
Subclasses that permit new mappings to be added must override put(K, V)
.
The default implementations of many methods are inefficient for large
maps. For example in the default implementation, each call to get(Object)
performs a linear iteration of the entry set. Subclasses should override such
methods to improve their performance.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
AbstractMap.SimpleEntry<K, V> | A key-value mapping with mutable values. | ||||||||||
AbstractMap.SimpleImmutableEntry<K, V> | An immutable key-value mapping. |
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Removes all elements from this
Map , leaving it empty.
This implementation calls | |||||||||||
Returns whether this
Map contains the specified key.
This implementation iterates its key set, looking for a key that
| |||||||||||
Returns whether this
Map contains the specified value.
This implementation iterates its entry set, looking for an entry with
a value that | |||||||||||
Returns a
Set containing all of the mappings in this Map .
| |||||||||||
Compares this instance with the specified object and indicates if they
are equal.
This implementation first checks the structure of | |||||||||||
Returns the value of the mapping with the specified key.
This implementation iterates its entry set, looking for an entry with
a key that | |||||||||||
Returns an integer hash code for this object.
This implementation iterates its entry set, summing the hashcodes of its entries. | |||||||||||
Returns whether this map is empty.
This implementation compares | |||||||||||
Returns a set of the keys contained in this
Map .
This implementation returns a view that calls through this to map. | |||||||||||
Maps the specified key to the specified value.
This base implementation throws | |||||||||||
Copies every mapping in the specified
Map to this Map .
This implementation iterates through | |||||||||||
Removes a mapping with the specified key from this
Map .
This implementation iterates its entry set, removing the entry with
a key that | |||||||||||
Returns the number of mappings in this
Map .
This implementation returns its entry set's size. | |||||||||||
Returns a string containing a concise, human-readable description of this
object.
This implementation composes a string by iterating its entry set. | |||||||||||
Returns a
Collection of the values contained in this Map .
This implementation returns a view that calls through this to map. |
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates and returns a copy of this
Object .
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
java.util.Map
|
Removes all elements from this Map
, leaving it empty.
This implementation calls entrySet().clear()
.
Returns whether this Map
contains the specified key.
This implementation iterates its key set, looking for a key that
key
equals.
key | the key to search for. |
---|
true
if this map contains the specified key,
false
otherwise.
Returns whether this Map
contains the specified value.
This implementation iterates its entry set, looking for an entry with
a value that value
equals.
value | the value to search for. |
---|
true
if this map contains the specified value,
false
otherwise.
Returns a Set
containing all of the mappings in this Map
. Each mapping is
an instance of Map.Entry
. As the Set
is backed by this Map
,
changes in one will be reflected in the other.
Compares this instance with the specified object and indicates if they
are equal. In order to be equal, o
must represent the same object
as this instance using a class-specific comparison. The general contract
is that this comparison should be reflexive, symmetric, and transitive.
Also, no object reference other than null is equal to null.
The default implementation returns true
only if this ==
o
. See Writing a correct
equals
method
if you intend implementing your own equals
method.
The general contract for the equals
and hashCode()
methods is that if equals
returns true
for
any two objects, then hashCode()
must return the same value for
these objects. This means that subclasses of Object
usually
override either both methods or neither of them.
This implementation first checks the structure of object
. If
it is not a map or of a different size, this returns false. Otherwise it
iterates its own entry set, looking up each entry's key in object
. If any value does not equal the other map's value for the same
key, this returns false. Otherwise it returns true.
object | the object to compare this instance with. |
---|
true
if the specified object is equal to this Object
; false
otherwise.Returns the value of the mapping with the specified key.
This implementation iterates its entry set, looking for an entry with
a key that key
equals.
key | the key. |
---|
null
if no mapping for the specified key is found.
Returns an integer hash code for this object. By contract, any two
objects for which equals(Object)
returns true
must return
the same hash code value. This means that subclasses of Object
usually override both methods or neither method.
Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct
hashCode
method
if you intend implementing your own hashCode
method.
This implementation iterates its entry set, summing the hashcodes of its entries.
Returns whether this map is empty.
This implementation compares size()
to 0.
true
if this map has no elements, false
otherwise.Returns a set of the keys contained in this Map
. The Set
is backed by
this Map
so changes to one are reflected by the other. The Set
does not
support adding.
This implementation returns a view that calls through this to map. Its iterator transforms this map's entry set iterator to return keys.
Maps the specified key to the specified value.
This base implementation throws UnsupportedOperationException
.
key | the key. |
---|---|
value | the value. |
null
if there was no mapping.Copies every mapping in the specified Map
to this Map
.
This implementation iterates through map
's entry set, calling
put()
for each.
map | the Map to copy mappings from. |
---|
Removes a mapping with the specified key from this Map
.
This implementation iterates its entry set, removing the entry with
a key that key
equals.
key | the key of the mapping to remove. |
---|
null
if no mapping
for the specified key was found.Returns the number of mappings in this Map
.
This implementation returns its entry set's size.
Map
.
Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:
getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toString
method
if you intend implementing your own toString
method.
This implementation composes a string by iterating its entry set. If this map contains itself as a key or a value, the string "(this Map)" will appear in its place.
Returns a Collection
of the values contained in this Map
. The Collection
is backed by this Map
so changes to one are reflected by the other. The
Collection
supports remove(Object)
, removeAll(Collection>)
,
retainAll(Collection>)
, and clear()
operations,
and it does not support add(E)
or addAll(Collection extends E>)
operations.
This method returns a Collection
which is the subclass of
AbstractCollection
. The iterator()
method of this subclass returns a
"wrapper object" over the iterator of this Map
's entrySet()
. The size()
method
wraps this Map
's size()
method and the contains(Object)
method wraps this Map
's
containsValue(Object)
method.
The collection is created when this method is called at first time and returned in response to all subsequent calls. This method may return different Collection when multiple calls to this method, since it has no synchronization performed.
This implementation returns a view that calls through this to map. Its iterator transforms this map's entry set iterator to return values.
Creates and returns a copy of this Object
. The default
implementation returns a so-called "shallow" copy: It creates a new
instance of the same class and then copies the field values (including
object references) from this instance to the new instance. A "deep" copy,
in contrast, would also recursively clone nested objects. A subclass that
needs to implement this kind of cloning should call super.clone()
to create the new instance and then create deep copies of the nested,
mutable objects.
CloneNotSupportedException |
---|