Java Reference
In-Depth Information
public SortedMap<K,V> subMap(K minKey, K maxKey)
Returns a view of the portion of the map whose keys are
greater than or equal to minKey and less than maxKey .
public SortedMap<K,V> headMap(K maxKey)
Returns a view of the portion of the map whose keys are less
than maxKey .
public SortedMap<K,V> tailMap(K minKey)
Returns a view of the portion of the map whose keys are
greater than or equal to minKey .
Any returned map is backed by the original map so changes made to
either are visible to the other.
A SortedMap is to Map what SortedSet is to Set and provides almost identical
functionality except that SortedMap works with keys. The exceptions
thrown by the SortedMap methods mirror those thrown by its SortedSet
counterparts.
The java.util package gives you four general-purpose Map implementa-
tions HashMap , LinkedHashMap , IdentityHashMap , and WeakHashMap and one Sor-
tedMap implementation, TReeMap .
21.8.1. HashMap
HashMap implements Map with a hashtable, where each key's hashCode
method is used to pick a place in the table. With a well-written hashCode
method, adding, removing, or finding a key/value pair is 0 (1). This
makes a HashMap a very efficient way to associate a key with a
value HashMap is one of the most commonly used collections. You already
have seen a HashMap in " Implementing Interfaces " on page 127 . The con-
structors for HashMap are
 
Search WWH ::




Custom Search