SortedMap Interface

SortedMap
  • SortedMap is the child interface of Map.
  • If we want to represent a group of key-value pairs according to some sorting order of keys then we should go for SortedMap.
  • Sorting is possible only based on the keys but not based on values.
  • It defines the following 6 specific methods.

1. Comparator comparator( )

Produces the comparator used for this Map, or null for natural ordering.

2. Object firstKey( )

Produces the lowest key.

3. Object lastKey( )

Produces the highest key.

4. SortedMap subMap(fromKey, toKey)

Produces a view of this Map with keys from fromKey, inclusive, to toKey, exclusive.

5. SortedMap headMap(toKey)

Produces a view of this Map with keys less than toKey.

6. SortedMap tailMap(fromKey)

Produces a view of this Map with keys greater than or equal to fromKey.

SortedMap Interface

Scroll to top