APIdia Launch Partner
Top Description Inners Fields Constructors Methods
java.util

public abstract Class AbstractMap<K, V>

extends Object
implements Map<K, V>
Class Inheritance
All Implemented Interfaces
java.util.Map
Known Direct Subclasses
java.util.Collections.EmptyMap, java.util.Collections.SingletonMap, java.util.EnumMap, java.util.HashMap, java.util.IdentityHashMap, java.util.ImmutableCollections.AbstractImmutableMap, java.util.LinkedHashMap.ReversedLinkedHashMapView, java.util.ReverseOrderSortedMapView, java.util.ReverseOrderSortedMapView.Submap, java.util.TreeMap, java.util.TreeMap.NavigableSubMap, java.util.TreeMap.SubMap, java.util.WeakHashMap, java.text.AttributedString.AttributeMap, java.util.concurrent.ConcurrentHashMap, java.util.concurrent.ConcurrentSkipListMap, java.util.concurrent.ConcurrentSkipListMap.SubMap, java.util.stream.Collectors.Partition, sun.util.PreHashedMap, java.lang.ProcessEnvironment.StringEnvironment
Annotations
@AOTSafeClassInitializer
Type Parameters
<K>
the type of keys maintained by this map
<V>
the type of mapped values
Imports
java.util.stream.Stream, java.util.function.Consumer, .IntFunction, .Predicate, jdk.internal.vm.annotation.AOTSafeClassInitializer

This class provides a skeletal implementation of the Map interface, to minimize the effort required to implement this interface.

To implement an unmodifiable map, the programmer needs only to extend this class and provide an implementation for the entrySet method, which returns a set-view of the map's mappings. Typically, the returned set will, in turn, be implemented atop AbstractSet. This set should not support the add or remove methods, and its iterator should not support the remove method.

To implement a modifiable map, the programmer must additionally override this class's put method (which otherwise throws an UnsupportedOperationException), and the iterator returned by entrySet().iterator() must additionally implement its remove method.

The programmer should generally provide a void (no argument) and map constructor, as per the recommendation in the Map interface specification.

The documentation for each non-abstract method in this class describes its implementation in detail. Each of these methods may be overridden if the map being implemented admits a more efficient implementation.

This class is a member of the Java Collections Framework.

Authors
Josh Bloch, Neal Gafter
Since
1.2
See Also
Map, Collection

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class
public static class
AbstractMap.SimpleEntry<
the type of key
K
,
the type of the value
V
>

An Entry maintaining a key and a value.

public static class
AbstractMap.SimpleImmutableEntry<
the type of the keys
K
,
the type of the value
V
>

An unmodifiable Entry maintaining a key and a value.

pack-priv class
pack-priv abstract static class
AbstractMap.ViewCollection<
the view's element type
E
>

Delegates all Collection methods to the provided non-sequenced map view, except add() and addAll(), which throw UOE.

Field Summary

Modifier and TypeField and Description
pack-priv transient Set<K>
keySet

Each of these fields are initialized to contain an instance of the appropriate view the first time this view is requested.

pack-priv transient Collection<V>

Constructor Summary

AccessConstructor and Description
protected
AbstractMap()

Sole constructor.

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Implements java.util.Map.clear.

Removes all of the mappings from this map (optional operation).

protected Object

Returns:

a shallow copy of this map
clone
()

Overrides java.lang.Object.clone.

Returns a shallow copy of this AbstractMap instance: the keys and values themselves are not cloned.

public boolean
containsKey(Object key)

Implements java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key.

public boolean
containsValue(Object value)

Implements java.util.Map.containsValue.

Returns true if this map maps one or more keys to the specified value.

public abstract Set<Map.Entry<K, V>>
entrySet()

Redeclares java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map.

private static boolean
eq(Object o1, Object o2)

Utility method for SimpleEntry and SimpleImmutableEntry.

public boolean

Returns:

true if the specified object is equal to this map
equals
(Object
object to be compared for equality with this map
o
)

Overrides java.lang.Object.equals.

Implements java.util.Map.equals.

Compares the specified object with this map for equality.

public V
get(Object key)

Implements java.util.Map.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

public int

Returns:

the hash code value for this map
hashCode
()

Overrides java.lang.Object.hashCode.

Implements java.util.Map.hashCode.

Returns the hash code value for this map.

public boolean
isEmpty()

Implements java.util.Map.isEmpty.

Returns true if this map contains no key-value mappings.

public Set<K>
keySet()

Implements java.util.Map.keySet.

Returns a Set view of the keys contained in this map.

public V
put(K key, V value)

Implements java.util.Map.put.

Associates the specified value with the specified key in this map (optional operation).

public void
putAll(Map<? extends K, ? extends V> m)

Implements java.util.Map.putAll.

Copies all of the mappings from the specified map to this map (optional operation).

public V
remove(Object key)

Implements java.util.Map.remove.

Removes the mapping for a key from this map if it is present (optional operation).

public int
size()

Implements java.util.Map.size.

Returns the number of key-value mappings in this map.

public String

Returns:

a string representation of this map
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of this map.

public Collection<V>
values()

Implements java.util.Map.values.

Returns a Collection view of the values contained in this map.

Inherited from java.lang.Object:
finalizegetClassnotifynotifyAllwaitwaitwait