Class AbstractMap<K,V>
java.lang.Object
java.util.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
public void clear()Removes all elements from this map, leaving it empty.- Specified by:
clearin interfaceMap<K,V> - Throws:
UnsupportedOperationException- if removing from this map is not supported.- See Also:
-
containsKey
Returns whether this map contains the specified key.- Specified by:
containsKeyin interfaceMap<K,V> - Parameters:
key- the key to search for.- Returns:
trueif this map contains the specified key,falseotherwise.
-
containsValue
Returns whether this map contains the specified value.- Specified by:
containsValuein interfaceMap<K,V> - Parameters:
value- the value to search for.- 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 ofMap.Entry. As the set is backed by this map, changes in one will be reflected in the other. -
equals
Compares the specified object to this instance, and returnstrueif the specified object is a map and both maps contain the same mappings. -
get
-
hashCode
-
isEmpty
-
keySet
-
put
Maps the specified key to the specified value.- Specified by:
putin interfaceMap<K,V> - Parameters:
key- the key.value- the value.- 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- 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- if the key or value isnulland this Map does not supportnullkeys or values.
-
putAll
Copies every mapping in the specified map to this map.- Specified by:
putAllin interfaceMap<K,V> - Parameters:
map- the map to copy mappings from.- Throws:
UnsupportedOperationException- if adding to this map is not supported.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- if a key or value isnulland this map does not supportnullkeys or values.
-
remove
Removes a mapping with the specified key from this Map.- Specified by:
removein interfaceMap<K,V> - Parameters:
key- the key of the mapping to remove.- Returns:
- the value of the removed mapping or
nullif no mapping for the specified key was found. - Throws:
UnsupportedOperationException- if removing from this map is not supported.
-
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.
-