java.util · java.base · since Java 1.2

SortedMap

declaration
public interface SortedMap<K, V> extends Map<K, V>

A Map that keeps its keys in ascending order, by natural ordering or a Comparator. Adds endpoint and range operations over Map.

Key methods

K firstKey() / lastKey()Lowest / highest key (throws if empty).
SortedMap<K, V> headMap(K to) / tailMap(K from)Range views over the key ordering.
SortedMap<K, V> subMap(K from, K to)Half-open [from, to) key-range view.
Comparator<? super K> comparator()The key ordering, or null for natural order.