Type Parameters:
E - the type of elements maintained by this set
All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, NavigableSet<E>, SequencedCollection<E>, SequencedSet<E>, Set<E>, SortedSet<E>

  • Constructor Summary

    Constructors

    TreeSet()

    Constructs a new, empty tree set, sorted according to the natural ordering of its elements.

    Constructs a new tree set containing the elements in the specified collection, sorted according to the natural ordering of its elements.

    Constructs a new, empty tree set, sorted according to the specified comparator.

    Constructs a new tree set containing the same elements and using the same ordering as the specified sorted set.

  • Method Summary

    boolean

    add(E e)

    Adds the specified element to this set if it is not already present.

    boolean

    Adds all of the elements in the specified collection to this set.

    void

    addFirst(E e)

    Throws UnsupportedOperationException.

    void

    addLast(E e)

    Throws UnsupportedOperationException.

    ceiling(E e)

    Returns the least element in this set greater than or equal to the given element, or null if there is no such element.

    void

    clear()

    Removes all of the elements from this set.

    clone()

    Returns a shallow copy of this TreeSet instance.

    Returns the comparator used to order the elements in this set, or null if this set uses the natural ordering of its elements.

    boolean

    Returns true if this set contains the specified element.

    Returns an iterator over the elements in this set in descending order.

    Returns a reverse order view of the elements contained in this set.

    first()

    Returns the first (lowest) element currently in this set.

    floor(E e)

    Returns the greatest element in this set less than or equal to the given element, or null if there is no such element.

    headSet(E toElement)

    Returns a view of the portion of this set whose elements are strictly less than toElement.

    headSet(E toElement, boolean inclusive)

    Returns a view of the portion of this set whose elements are less than (or equal to, if inclusive is true) toElement.

    higher(E e)

    Returns the least element in this set strictly greater than the given element, or null if there is no such element.

    boolean

    isEmpty()

    Returns true if this set contains no elements.

    iterator()

    Returns an iterator over the elements in this set in ascending order.

    last()

    Returns the last (highest) element currently in this set.

    lower(E e)

    Returns the greatest element in this set strictly less than the given element, or null if there is no such element.

    pollFirst()

    Retrieves and removes the first (lowest) element, or returns null if this set is empty (optional operation).

    pollLast()

    Retrieves and removes the last (highest) element, or returns null if this set is empty (optional operation).

    boolean

    Removes the specified element from this set if it is present.

    int

    size()

    Returns the number of elements in this set (its cardinality).

    subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive)

    Returns a view of the portion of this set whose elements range from fromElement to toElement.

    subSet(E fromElement, E toElement)

    Returns a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive.

    tailSet(E fromElement)

    Returns a view of the portion of this set whose elements are greater than or equal to fromElement.

    tailSet(E fromElement, boolean inclusive)

    Returns a view of the portion of this set whose elements are greater than (or equal to, if inclusive is true) fromElement.

    Methods declared in class AbstractSet

    equals, hashCode, removeAll

    boolean

    Compares the specified object with this set for equality.

    int

    Returns the hash code value for this set.

    boolean

    Removes from this set all of its elements that are contained in the specified collection (optional operation).

    Methods declared in class AbstractCollection

    containsAll, retainAll, toArray, toArray, toString

    boolean

    Returns true if this collection contains all of the elements in the specified collection.

    boolean

    Retains only the elements in this collection that are contained in the specified collection (optional operation).

    Returns an array containing all of the elements in this collection.

    <T> T[]

    Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array.

    Returns a string representation of this collection.

    Methods declared in class Object

    finalize, getClass, notify, notifyAll, wait, wait, wait

    protected void

    Deprecated, for removal: This API element is subject to removal in a future version.

    Returns the runtime class of this Object.

    final void

    Wakes up a single thread that is waiting on this object's monitor.

    final void

    Wakes up all threads that are waiting on this object's monitor.

    final void

    Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

    final void

    wait(long timeoutMillis)

    Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

    final void

    wait(long timeoutMillis, int nanos)

    Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

    Methods declared in interface Collection

    parallelStream, removeIf, stream, toArray

    Returns a possibly parallel Stream with this collection as its source.

    default boolean

    Removes all of the elements of this collection that satisfy the given predicate (optional operation).

    Returns a sequential Stream with this collection as its source.

    default <T> T[]

    Returns an array containing all of the elements in this collection, using the provided generator function to allocate the returned array.

    Methods declared in interface Iterable

    forEach

    default void

    Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception.

    Methods declared in interface NavigableSet

    removeFirst, removeLast, reversed

    default E

    Removes and returns the first element of this collection (optional operation).

    default E

    Removes and returns the last element of this collection (optional operation).

    Returns a reverse-ordered view of this collection.

    Methods declared in interface Set

    containsAll, retainAll, toArray, toArray

    boolean

    Returns true if this set contains all of the elements of the specified collection.

    boolean

    Retains only the elements in this set that are contained in the specified collection (optional operation).

    Returns an array containing all of the elements in this set.

    <T> T[]

    Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array.

    Methods declared in interface SortedSet

    getFirst, getLast

    default E

    Gets the first element of this collection.

    default E

    Gets the last element of this collection.

  • Constructor Details

    • TreeSet

    • TreeSet

    • TreeSet

    • TreeSet

  • Method Details

    • iterator

    • descendingIterator

    • descendingSet

    • size

    • isEmpty

    • contains

    • add

    • remove

    • clear

    • addAll

    • subSet

    • headSet

    • tailSet

    • subSet

    • headSet

    • tailSet

    • comparator

    • first

    • last

    • lower

    • floor

    • ceiling

    • higher

    • pollFirst

    • pollLast

    • addFirst

    • addLast

    • clone

    • spliterator