The SortedSet interface extends Set and declares the behavior of a set sorted in ascending order. SortedSet is a generic interface that has this declaration:
interface SortedSet<E>
Here, E specifies the type of objects that the set will hold.
The NavigableSet Interface
The NavigableSet interface was added by Java SE 6. It extends SortedSet and declares the behavior of a collection that supports the retrieval of elements based on the closest match to a given value or values. NavigableSet is a generic interface that has this declaration:
interface NavigableSet<E>
Method | Description |
Comparator<? super E> comparator( ) | Returns the invoking sorted set’s comparator. If the natural ordering |
is used for this set, null is returned. | |
E first( ) | Returns the first element in the invoking sorted set. |
SortedSet<E> headSet(E end) | Returns a SortedSet containing those elements less than end that |
are contained in the invoking sorted set. Elements in the returned | |
sorted set are also referenced by the invoking sorted set. | |
E last( ) | Returns the last element in the invoking sorted set. |
SortedSet<E> subSet(E start, E end) | Returns a SortedSet that includes those elements between start |
and end–1. Elements in the returned collection are also referenced | |
by the invoking object. | |
SortedSet<E> tailSet(E start) | Returns a SortedSet that contains those elements greater than or |
equal to start that are contained in the sorted set. Elements in the | |
returned set are also referenced by the invoking object. |
Method | Description | |
E ceiling(E obj) | Searches the set for the smallest element e such that e >= obj. If | |
such an element is found, it is returned. Otherwise, null is returned. | ||
Iterator<E> descendingIterator( ) | Returns an iterator that moves from the greatest to least. In | |
other words, it returns a reverse iterator. | ||
NavigableSet<E> descendingSet( ) | Returns a NavigableSet that is the reverse of the invoking set. | |
The resulting set is backed by the invoking set. | ||
E floor(E obj) | Searches the set for the largest element e such that e <= obj. If | |
such an element is found, it is returned. Otherwise, null is | ||
returned. | ||
NavigableSet<E> | Returns a NavigableSet that includes all elements from the | |
headSet(E upperBound, boolean incl) | invoking set that are less than upperBound. If incl is true, then | |
an element equal to upperBound is included. The resulting set is | ||
backed by the invoking set. | ||
E higher(E obj) | Searches the set for the largest element e such that e > obj. If such | |
an element is found, it is returned. Otherwise, null is returned. | ||
E lower(E obj) | Searches the set for the largest element e such that e < obj. If | |
such an element is found, it is returned. Otherwise, null is | ||
returned. | ||
E pollFirst( ) | Returns the first element, removing the element in the process. | |
Because the set is sorted, this is the element with the least | ||
value. null is returned if the set is empty. | ||
E pollLast( ) | Returns the last element, removing the element in the process. | |
Because the set is sorted, this is the element with the greatest | ||
value. null is returned if the set is empty. | ||
NavigableSet<E> | Returns a NavigableSet that includes all elements from the | |
subSet(E lowerBound, | invoking set that are greater than lowerBound and less than | |
boolean lowIncl, | upperBound. If lowIncl is true, then an element equal to | |
E upperBound, | lowerBound is included. If highIncl is true, then an element | |
boolean highIncl) | equal to upperBound is included. The resulting set is backed | |
by the invoking set. | ||
NavigableSet<E> | Returns a NavigableSet that includes all elements from the | |
tailSet(E lowerBound, boolean incl) | invoking set that are greater than lowerBound. If incl is true, then | |
an element equal to lowerBound is included. The resulting set is | ||
backed by the invoking set. |