E
- the type of elements maintained by this setpublic interface NavigableSet<E> extends SortedSet<E>
SortedSet
extended with navigation methods reporting
closest matches for given search targets. Methods lower,
floor, ceiling, and higher return keys
respectively less than, less than or equal, greater than or equal,
and greater than a given key, returning null if there is
no such key. A NavigableSet may be viewed and traversed
in either ascending or descending order. The Collection
iterator method returns an ascending Iterator and
the additional method descendingIterator returns
descending iterator. The performance of ascending traversals is
likely to be faster than descending traversals. This interface
additionally defines methods pollFirst and
The return values of navigation methods may be ambiguous in
implementations that permit null elements. However, even
in this case the result can be disambiguated by checking
contains(null). To avoid such issues, implementations of
this interface are encouraged not to permit insertion of
null elements. (Note that sorted sets of Comparable
elements intrinsically do not permit null.)
Modifier and Type | Method and Description |
---|---|
E |
ceiling(E o)
Returns an element greater than or equal to the given element, or
null if there is no such element.
|
Iterator<E> |
descendingIterator()
Returns an iterator over the elements in this collection, in
descending order.
|
E |
floor(E o)
Returns an element less than or equal to the given element, or
null if there is no such element.
|
NavigableSet<E> |
headSet(E toElement)
Returns a view of the portion of this set whose elements are strictly
less than toElement.
|
E |
higher(E o)
Returns an element strictly greater than the given element, or
null if there is no such element.
|
E |
lower(E o)
Returns an element strictly less than the given element, or
null if there is no such element.
|
E |
pollFirst()
Retrieves and removes the first (lowest) element.
|
E |
pollLast()
Retrieves and removes the last (highest) element.
|
NavigableSet<E> |
subSet(E fromElement,
E toElement)
Returns a view of the portion of this set whose elements range from
fromElement, inclusive, to toElement, exclusive.
|
NavigableSet<E> |
tailSet(E fromElement)
Returns a view of the portion of this set whose elements are
greater than or equal to fromElement.
|
comparator, first, last
E ceiling(E o)
o
- the value to matchClassCastException
- if o cannot be compared with the elements
currently in the set.NullPointerException
- if o is null
and this set deas not permit null elementsE lower(E o)
o
- the value to matchClassCastException
- if o cannot be compared with the elements
currently in the set.NullPointerException
- if o is null
and this set deas not permit null elementsE floor(E o)
o
- the value to matchClassCastException
- if o cannot be compared with the elements
currently in the set.NullPointerException
- if o is null.
and this set deas not permit null elementsE higher(E o)
o
- the value to matchClassCastException
- if o cannot be compared with the elements
currently in the set.NullPointerException
- if o is null
and this set deas not permit null elementsE pollFirst()
E pollLast()
Iterator<E> descendingIterator()
NavigableSet<E> subSet(E fromElement, E toElement)
subSet
in interface SortedSet<E>
fromElement
- low endpoint (inclusive) of the subSet.toElement
- high endpoint (exclusive) of the subSet.ClassCastException
- if fromElement and
toElement cannot be compared to one another using
this set's comparator (or, if the set has no comparator,
using natural ordering).IllegalArgumentException
- if fromElement is
greater than toElement.NullPointerException
- if fromElement or
toElement is null
and this set deas not permit null elementsNavigableSet<E> headSet(E toElement)
headSet
in interface SortedSet<E>
toElement
- high endpoint (exclusive) of the headSet.ClassCastException
- if toElement is not compatible
with this set's comparator (or, if the set has no comparator,
if toElement does not implement Comparable).NullPointerException
- if toElement is null
and this set deas not permit null elementsNavigableSet<E> tailSet(E fromElement)
tailSet
in interface SortedSet<E>
fromElement
- low endpoint (inclusive) of the tailSet.ClassCastException
- if fromElement is not
compatible with this set's comparator (or, if the set has no
comparator, if fromElement does not implement
Comparable).NullPointerException
- if fromElement is null
and this set deas not permit null elements