java.util · java.base · since Java 1.2

SortedSet

declaration
public interface SortedSet<E> extends Set<E>

A Set that maintains its elements in ascending order, by natural ordering or a supplied Comparator. Adds endpoint and range operations over Set.

Key methods

E first() / E last()Lowest / highest element (throws if empty).
SortedSet<E> headSet(E to) / tailSet(E from)Range views: strictly-below / at-or-above.
SortedSet<E> subSet(E from, E to)Half-open [from, to) range view.
Comparator<? super E> comparator()The ordering in use, or null for natural order.