A SortedMap is a Java collection that holds elements in key-value pairs and has a total ordering on its keys, similar to a Map. On the map, duplicate items are not permitted.
SortedMap is a collection foundation interface. This interface extends the Map interface by allowing the elements to be ordered in their entirety (elements can be traversed in sorted order of keys). TreeMap is the class that implements this interface.
A SortedMap's primary feature is arranging the keys either by their natural ordering or by a given comparator. When you need a map that meets the following characteristics, consider utilising a TreeMap:
It is impossible to have a null key or a null value, and natural ordering or a defined comparator are used to sort the keys. The SortedMap interface is a Map extension, and it makes sure that the entries are kept in ascending key order.
When there are no elements in the invoking map, some methods raise a NoSuchElementException. When an object is incompatible with the items in a map, a ClassCastException is produced. If a null object is attempted to be used while null is not allowed in the map, a NullPointerException is issued.
A Map that also has a complete ordering for its keys. The map is sorted either by order of its keys or by a Comparator generally given at the time of sorted map construction. This order is visible when it is repeated over a filter map view (returned by the entrySet, keySet, and values methods). To make use of the ordering, many different procedures are available. (This is the map equivalent of SortedSet.)
The Comparable interface must be implemented by all keys placed into a sorted map (or be accepted by the specified comparator). In addition, all of these keys must be changed:
k1. Compare For all k1 and k2 keys on a sorted map, For (k2) (or comparison. compare(k1, k2)) must not cause a ClassCastException. Any attempt to circumvent this restriction will result in a ClassCastException being thrown by the offending method or function Object() { [native code] } call.
Sub = m.subMap(low, high+"0"); SortedMapString, V> sub = m.subMap(low, high+"0");
An open range can be created using a similar method (which contains neither endpoint). The following phrase gets a view of all the key-value mappings in m whose keys are between low and high, but not both:
sub = m.subMap(low+"0", high); SortedMapString, V>