Skip to content

Most visited

Recently visited

navigation
Added in API level 1

SortedSet

public interface SortedSet
implements Set<E>

java.util.SortedSet<E>
Known Indirect Subclasses


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 a Comparator which 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 with equals of its elements.

See also:

Summary

Public methods

abstract Comparator<? super E> comparator()

Returns the comparator used to compare elements in this SortedSet.

abstract E first()

Returns the first element in this SortedSet.

abstract SortedSet<E> headSet(E end)

Returns a SortedSet of the specified portion of this SortedSet which contains elements less than the end element.

abstract E last()

Returns the last element in this SortedSet.

abstract SortedSet<E> subSet(E start, E end)

Returns a SortedSet of the specified portion of this SortedSet which contains elements greater or equal to the start element but less than the end element.

abstract SortedSet<E> tailSet(E start)

Returns a SortedSet of the specified portion of this SortedSet which contains elements greater or equal to the start element.

Inherited methods

From interface java.util.Set
From interface java.util.Collection
From interface java.lang.Iterable

Public methods

comparator

Added in API level 1
Comparator<? super E> comparator ()

Returns the comparator used to compare elements in this SortedSet.

Returns
Comparator<? super E> a comparator or null if the natural ordering is used.

first

Added in API level 1
E first ()

Returns the first element in this SortedSet. The first element is the lowest element.

Returns
E the first element.
Throws
NoSuchElementException when this SortedSet is empty.

headSet

Added in API level 1
SortedSet<E> headSet (E end)

Returns a SortedSet of the specified portion of this SortedSet which contains elements less than the end element. The returned SortedSet is backed by this SortedSet so changes to one set are reflected by the other.

Parameters
end E: the end element.
Returns
SortedSet<E> 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 this SortedSet does not support null elements.

last

Added in API level 1
E last ()

Returns the last element in this SortedSet. The last element is the highest element.

Returns
E the last element.
Throws
NoSuchElementException when this SortedSet is empty.

subSet

Added in API level 1
SortedSet<E> subSet (E start, 
                E end)

Returns a SortedSet of the specified portion of this SortedSet which contains elements greater or equal to the start element but less than the end element. The returned SortedSet is backed by this SortedMap so changes to one set are reflected by the other.

Parameters
start E: the start element.
end E: the end element.
Returns
SortedSet<E> a subset where the elements are greater or equal to start and less than end.
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 this SortedSet does not support null elements.
IllegalArgumentException when the start element is greater than the end element.

tailSet

Added in API level 1
SortedSet<E> tailSet (E start)

Returns a SortedSet of the specified portion of this SortedSet which contains elements greater or equal to the start element. The returned SortedSet is backed by this SortedSet so changes to one set are reflected by the other.

Parameters
start E: the start element.
Returns
SortedSet<E> 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 this SortedSet does not support null elements.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.