- SortedMap is the child interface of map
- When you want to represent a map keys in some sorting order then we should for for SortedMap.
- Sorting is based on the keys and not based on values
Features of SortedMap :
- When you want to represent a map keys in some sorting order then we should for for SortedMap.
Methods :
- Object first()
- Object last()
- SortedMap headMap(key k) – returns a map with keys which is less than passed K
- SortedMap tailMap(key k) – returns a map with keys which are greater and equal to K
- SortedMap subMap(Object o1, Object o2) – returns a map with keys in that range only head inclusive
- Comparator comparator()
- It is going to show the internal sorting technique
- If it is using default sorting order then it returns null
- Default natural sorting order of number is Ascending
- Default natural sorting order of String is Alphabetic
Example :