Collection Framework - SortedMap, NavigableMap and TreeMap

SortedMap is the child of Map interface. As was the case with SortedSet, SortedMap stores the keys based on a particular sorting order.

SortedMap comes with methods similar to SortedSet as follows :

firstKey() - returns first key
lastKey() - returns last key
headMap(key) - returns map of keys before the specified key
tailMap(key) - returns map of keys after the specified key including it
subMap(key) - returns map of keys between initial and final key including the initial key
comparator() - returns use comparator else null

Similar to NavigableSet, NavigableMap also provides with the methods for searching :

lowerKey()
lowerEntry()
floorKey()
floorEntry()
ceilingKey()
ceilingEntry()
higherKey()
higherEntry()
pollFirstEntry()
pollLastEntry()

TreeMap is the implementation class of NavigableMap. It provides default constructor as well as comparator constructor.

The working of TreeMap is similar to TreeSet. The example of TreeMap can be found here

Comments

Popular posts from this blog

Collection Framework - HashSet And LinkedHashSet class

Collection Framework - Cursors in Java

Hashed data structures