java.util
public
abstract
class
java.util.AbstractMap<K, V>
AbstractMap is an abstract implementation of the Map interface. This
Implementation does not support adding. A subclass must implement the
abstract method entrySet().
Known Direct Subclasses
ConcurrentHashMap<K, V>,
EnumMap<K extends
Enum<K>, V>,
HashMap<K, V>,
IdentityHashMap<K, V>,
TreeMap<K, V>,
WeakHashMap<K, V>
ConcurrentHashMap<K, V> |
A hash table supporting full concurrency of retrievals and
adjustable expected concurrency for updates. |
EnumMap<K extends Enum<K>, V> |
|
HashMap<K, V> |
HashMap is an implementation of Map. |
IdentityHashMap<K, V> |
IdentityHashMap
This is a variant on HashMap which tests equality by reference instead of by
value. |
TreeMap<K, V> |
TreeMap is an implementation of SortedMap. |
WeakHashMap<K, V> |
WeakHashMap is an implementation of Map with keys which are WeakReferences. |
Known Indirect Subclasses
Summary
Protected Constructors
Public Methods
Protected Methods
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Methods inherited
from interface
java.util.Map
clear,
containsKey,
containsValue,
entrySet,
equals,
get,
hashCode,
isEmpty,
keySet,
put,
putAll,
remove,
size,
values
Details
Protected Constructors
protected
AbstractMap()
Constructs a new instance of this AbstractMap.
Public Methods
public
void
clear()
Removes all elements from this Map, leaving it empty.
public
boolean
containsKey(Object key)
Searches this Map for the specified key.
Parameters
key
| the object to search for |
Returns
- true if
key
is a key of this Map, false otherwise
public
boolean
containsValue(Object value)
Searches this Map for the specified value.
Parameters
value
| the object to search for |
Returns
- true if
value
is a value of this Map, false
otherwise
public
abstract
Set<Entry<K, V>>
entrySet()
Returns a set view of the mappings contained in this map. Each element in
this set is a Map.Entry. The set is backed by the map so changes to one
are reflected by the other. (If the map is modified while an iteration
over the set is in progress, the results of the iteration are undefined.)
The set supports remove, removeAll, retainAll and clear operations, and
it does not support add or addAll operations.
Returns
- a set of the mappings contained in this map
public
boolean
equals(Object object)
Compares the specified object to this Map and answer if they are equal.
The object must be an instance of Map and contain the same key/value
pairs.
Parameters
object
| the object to compare with this object |
Returns
- true if the specified object is equal to this Map, false
otherwise
public
V
get(Object key)
Returns the value of the mapping with the specified key.
Returns
- the value of the mapping with the specified key
public
int
hashCode()
Returns an integer hash code for the receiver. Objects which are equal
answer the same value for this method.
public
boolean
isEmpty()
Returns if this Map has no elements, a size of zero.
Returns
- true if this Map has no elements, false otherwise
public
Set<K>
keySet()
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.
public
V
put(K key, V value)
Maps the specified key to the specified value.
Parameters
key
| the key |
value
| the value |
Returns
- the value of any previous mapping with the specified key or null
if there was no mapping
public
void
putAll(Map<? extends K, ? extends V> map)
Copies every mapping in the specified Map to this Map.
Parameters
map
| the Map to copy mappings from |
public
V
remove(Object key)
Removes a mapping with the specified key from this Map.
Parameters
key
| the key of the mapping to remove |
Returns
- the value of the removed mapping or null if key is not a key in
this Map
public
int
size()
Returns the number of elements in this Map.
Returns
- the number of elements in this Map
public
String
toString()
Returns the string representation of this Map.
Returns
- the string representation of this Map
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 size method
wraps the map's size method and the contains method wraps the map's
containsValue 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.
Returns
- a collection of the values contained in this map
Protected Methods
protected
Object
clone()
Returns a new instance of the same class as the receiver, whose slots
have been filled in with the values in the slots of the receiver.
Returns
- Object a shallow copy of this object.