What is MAP and SortedMap interface?A Map is an object that maps keys to values. It is not an extension of the collection interface rather it has own interface hierarchy. Map provides a more general way for storing elements without containing duplicate keys. It allows you to store pairs of elements, termed "keys" and "values", where each key maps to one value. Thus the keys in a map must be unique.
Each element in a map has a key and value. Each key-value pair is saved in a java.util.Map. Entry object. A set of these map entries can be obtained by calling a map's entrySet( ) method.
SortedMap interface:
The Collection Framework provides a special Map interface for maintaining elements in a sorted order called SortedMap. The SortedMap interface extends the Map interface which maintains its elements in ascending order. Working with a SortedMap is just similar to a SortedSet except, the sort is done on the map keys. In addition to methods of the Map interface, it provides two methods:
The firstKey( ) method returns the first lowest value currently in the map while the lastKey( ) method returns the last highest value currently in the map.
|