Java Reference
In-Depth Information
You can obtain a set of the keys in the map using the keySet() method, and a collection
of the values in the map using the values() method. The entrySet() method returns a set
of entries. The entries are instances of the Map.Entry<K, V> interface, where Entry is an
inner interface for the Map interface, as shown in Figure 21.5. Each entry in the set is a key/
value pair in the underlying map.
keySet()
values()
entrySet()
«interface»
java.util.Map.Entry<K,V>
+getKey(): K
+getValue(): V
+setValue(value: V): void
Returns the key from this entry.
Returns the value from this entry.
Replaces the value in this entry with a new value.
F IGURE 21.5
The Map.Entry interface operates on an entry in the map.
The AbstractMap class is a convenience abstract class that implements all the methods in
the Map interface except the entrySet() method.
The HashMap , LinkedHashMap , and TreeMap classes are three concrete implementations
of the Map interface, as shown in Figure 21.6.
AbstractMap
concrete implementations
«interface»
java.util.Map<K, V>
java.util.AbstractMap<K,V>
«interface»
java.util.SortedMap<K,V>
+ firstKey(): K
+ lastKey(): K
+ comparator(): Comparator<? super K>)
+ headMap(toKey: K): SortedMap<K,V>
+ tailMap(fromKey: K): SortedMap<K,V>
java.util.HashMap<K,V>
+HashMap()
+HashMap(initialCapacity: int,loadFactor: float)
+HashMap(m: Map<? extends K, ? extends V>)
java.util.LinkedHashMap<K,V>
+LinkedHashMap()
+LinkedHashMap(m: Map<? extends K,? extends V>)
+LinkedHashMap(initialCapacity: int,
loadFactor: float, accessOrder: boolean)
«interface»
java.util.NavigableMap<K, V>
+ floorKey(key: K): K
+ ceilingKey(key: K): K
+ lowerKey(key: K): K
+ higherKey(key: K): K
+ pollFirstEntry(): Map.EntrySet<K, V>
+ pollLastEntry(): Map.EntrySet<K, V>
java.util.TreeMap<K,V>
+TreeMap()
+TreeMap(m: Map<? extends K,? extends V>)
+TreeMap(c: Comparator<? super K>)
F IGURE 21.6
The Java Collections Framework provides three concrete map classes.
 
 
Search WWH ::




Custom Search