Java Reference
In-Depth Information
There are three types of maps: HashMap , LinkedHashMap , and TreeMap . The com-
mon features of these maps are defined in the Map interface. Their relationship is shown in
Figure 21.3.
SortedMap
NavigableMap
TreeMap
AbstractMap
Map
HashMap
LinkedHashMap
Interfaces
Abstract Classes
Concrete Classes
F IGURE 21.3
A map stores key/value pairs.
The Map interface provides the methods for querying, updating, and obtaining a collection
of values and a set of keys, as shown in Figure 21.4.
«interface»
java.util.Map<K,V>
+ clear(): void
Removes all entries from this map.
+ containsKey(key: Object): boolean
Returns true if this map contains an entry for the
specified key.
Returns true if this map maps one or more keys to the
specified value.
Returns a set consisting of the entries in this map.
Returns the value for the specified key in this map.
Returns true if this map contains no entries.
Returns a set consisting of the keys in this map.
Puts an entry into this map.
+ containsValue(value: Object): boolean
+ entrySet(): Set<Map.Entry<K,V>>
+ get(key: Object): V
+ isEmpty(): boolean
+ keySet(): Set<K>
+ put(key: K, value: V): V
+ putAll(m: Map<? extends K,? extends
V>): void
Adds all the entries from m to this map.
+ remove(key: Object): V
+ size(): int
+ values(): Collection<V>
Removes the entries for the specified key.
Returns the number of entries in this map.
Returns a collection consisting of the values in this map.
F IGURE 21.4
The Map interface maps keys to values.
The update methods include clear , put , putAll , and remove . The clear() method
removes all entries from the map. The put(K key, V value) method adds an entry for the
specified key and value in the map. If the map formerly contained an entry for this key, the
old value is replaced by the new value and the old value associated with the key is returned.
The putAll(Map m) method adds all entries in m to this map. The remove(Object key)
method removes the entry for the specified key from the map.
The query methods include containsKey , containsValue , isEmpty , and size . The
containsKey(Object key) method checks whether the map contains an entry for the
specified key. The containsValue(Object value) method checks whether the map con-
tains an entry for this value. The isEmpty() method checks whether the map contains any
entries. The size() method returns the number of entries in the map.
update methods
query methods
 
 
Search WWH ::




Custom Search