Package java.util
Interface SortedSet<E>
-
- All Superinterfaces:
Collection<E>,Iterable<E>,Set<E>
- All Known Subinterfaces:
NavigableSet<E>
- All Known Implementing Classes:
ConcurrentSkipListSet,TreeSet
public interface SortedSet<E> extends Set<E>
SortedSet is a Set which iterates over its elements in a sorted order. The order is determined either by the elements natural ordering, or by aComparatorwhich is passed into a concrete implementation at construction time. All elements in this set must be mutually comparable. The ordering in this set must be consistent withequalsof its elements.- See Also:
Comparator,Comparable
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Comparator<? super E>comparator()Returns the comparator used to compare elements in thisSortedSet.Efirst()Returns the first element in thisSortedSet.SortedSet<E>headSet(E end)Returns aSortedSetof the specified portion of thisSortedSetwhich contains elements less than the end element.Elast()Returns the last element in thisSortedSet.SortedSet<E>subSet(E start, E end)Returns aSortedSetof the specified portion of thisSortedSetwhich contains elements greater or equal to the start element but less than the end element.SortedSet<E>tailSet(E start)Returns aSortedSetof the specified portion of thisSortedSetwhich contains elements greater or equal to the start element.
-
-
-
Method Detail
-
comparator
Comparator<? super E> comparator()
Returns the comparator used to compare elements in thisSortedSet.- Returns:
- a comparator or null if the natural ordering is used.
-
first
E first()
Returns the first element in thisSortedSet. The first element is the lowest element.- Returns:
- the first element.
- Throws:
NoSuchElementException- when thisSortedSetis empty.
-
headSet
SortedSet<E> headSet(E end)
Returns aSortedSetof the specified portion of thisSortedSetwhich contains elements less than the end element. The returnedSortedSetis backed by thisSortedSetso changes to one set are reflected by the other.- Parameters:
end- the end element.- Returns:
- a subset where the elements are less than
end. - Throws:
ClassCastException- when the class of the end element is inappropriate for this SubSet.NullPointerException- when the end element is null and thisSortedSetdoes not support null elements.
-
last
E last()
Returns the last element in thisSortedSet. The last element is the highest element.- Returns:
- the last element.
- Throws:
NoSuchElementException- when thisSortedSetis empty.
-
subSet
SortedSet<E> subSet(E start, E end)
Returns aSortedSetof the specified portion of thisSortedSetwhich contains elements greater or equal to the start element but less than the end element. The returnedSortedSetis backed by this SortedMap so changes to one set are reflected by the other.- Parameters:
start- the start element.end- the end element.- Returns:
- a subset where the elements are greater or equal to
startand less thanend. - Throws:
ClassCastException- when the class of the start or end element is inappropriate for this SubSet.NullPointerException- when the start or end element is null and thisSortedSetdoes not support null elements.IllegalArgumentException- when the start element is greater than the end element.
-
tailSet
SortedSet<E> tailSet(E start)
Returns aSortedSetof the specified portion of thisSortedSetwhich contains elements greater or equal to the start element. The returnedSortedSetis backed by thisSortedSetso changes to one set are reflected by the other.- Parameters:
start- the start element.- Returns:
- a subset where the elements are greater or equal to
start. - Throws:
ClassCastException- when the class of the start element is inappropriate for this SubSet.NullPointerException- when the start element is null and thisSortedSetdoes not support null elements.
-
-