Class AbstractMap<K,V>
- All Implemented Interfaces:
Map<K,V>
- Direct Known Subclasses:
HashMap, IdentityHashMap, TreeMap
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA key-value mapping.static classAn immutable key-value mapping. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs a new instance of thisAbstractMap. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all elements from this map, leaving it empty.booleancontainsKey(Object key) Returns whether this map contains the specified key.booleancontainsValue(Object value) Returns whether this map contains the specified value.entrySet()Returns a set containing all of the mappings in this map.booleanCompares the specified object to this instance, and returnstrueif the specified object is a map and both maps contain the same mappings.Returns the value of the mapping with the specified key.inthashCode()Returns the hash code for this object.booleanisEmpty()Returns whether this map is empty.keySet()Returns a set of the keys contained in this map.Maps the specified key to the specified value.voidCopies every mapping in the specified map to this map.Removes a mapping with the specified key from this Map.intsize()Returns the number of elements in this map.toString()Returns the string representation of this map.values()Returns a collection of the values contained in this map.
-
Constructor Details
-
AbstractMap
protected AbstractMap()Constructs a new instance of thisAbstractMap.
-
-
Method Details
-
clear
-
containsKey
Returns whether this map contains the specified key.
Parameters
key: the key to search for.
Returns
- Specified by:
containsKeyin interfaceMap<K,V> - Returns:
trueif this map contains the specified key,falseotherwise.
-
containsValue
Returns whether this map contains the specified value.
Parameters
value: the value to search for.
Returns
- Specified by:
containsValuein interfaceMap<K,V> - Returns:
trueif this map contains the specified value,falseotherwise.
-
entrySet
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.Returns
a set of the mappings.
-
equals
Compares the specified object to this instance, and returns
trueif the specified object is a map and both maps contain the same mappings.Parameters
object: the object to compare with this object.
Returns
-
get
-
hashCode
-
isEmpty
-
keySet
-
put
Maps the specified key to the specified value.
Parameters
-
key: the key. -
value: the value.
Returns
- Specified by:
putin interfaceMap<K,V> - Returns:
the value of any previous mapping with the specified key or
nullif there was no mapping.Throws
-
UnsupportedOperationException: if adding to this map is not supported. -
ClassCastException: @throws ClassCastException if the class of the key or value is inappropriate for this map. -
IllegalArgumentException: if the key or value cannot be added to this map. -
NullPointerException: @throws NullPointerException if the key or value isnulland this Map does not supportnullkeys or values.
-
-
-
putAll
Copies every mapping in the specified map to this map.
Parameters
map: the map to copy mappings from.
Throws
-
UnsupportedOperationException: if adding to this map is not supported. -
ClassCastException: @throws ClassCastException if the class of a key or value is inappropriate for this map. -
IllegalArgumentException: if a key or value cannot be added to this map. -
NullPointerException: @throws NullPointerException if a key or value isnulland this map does not supportnullkeys or values.
-
remove
Removes a mapping with the specified key from this Map.
Parameters
key: the key of the mapping to remove.
Returns
-
size
-
toString
-
values
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, removeAll, retainAll and clear operations, and it does not support add or addAll 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 map's entrySet(). The
sizemethod wraps the map's size method and thecontainsmethod wraps the map's containsValue method.The collection is created when this method is called for the first time and returned in response to all subsequent calls. This method may return different collections when multiple concurrent calls occur to this method, since no synchronization is performed.
Returns
a collection of the values contained in this map.
-