Added in API level 35

SequencedSet

public interface SequencedSet
implements SequencedCollection<E>, Set<E>

java.util.SequencedSet<E>
ConcurrentSkipListSet<E> A scalable concurrent NavigableSet implementation based on a ConcurrentSkipListMap
LinkedHashSet<E>

Hash table and linked list implementation of the Set interface, with well-defined encounter order. 

NavigableSet<E> A SortedSet extended with navigation methods reporting closest matches for given search targets. 
SortedSet<E> A Set that further provides a total ordering on its elements. 
TreeSet<E> A NavigableSet implementation based on a TreeMap


A collection that is both a SequencedCollection and a Set. As such, it can be thought of either as a Set that also has a well-defined encounter order, or as a SequencedCollection that also has unique elements.

This interface has the same requirements on the equals and hashCode methods as defined by Set.equals and Set.hashCode. Thus, a Set and a SequencedSet will compare equals if and only if they have equal elements, irrespective of ordering.

SequencedSet defines the reversed() method, which provides a reverse-ordered view of this set. The only difference from the SequencedCollection.reversed method is that the return type of SequencedSet.reversed is SequencedSet.

This class is a member of the Java Collections Framework.

Summary

Public methods

abstract SequencedSet<E> reversed()

Returns a reverse-ordered view of this collection.

Inherited methods

default void addFirst(E e)

Adds an element as the first element of this collection (optional operation).

default void addLast(E e)

Adds an element as the last element of this collection (optional operation).

default E getFirst()

Gets the first element of this collection.

default E getLast()

Gets the last element of this collection.

default E removeFirst()

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

default E removeLast()

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

abstract SequencedCollection<E> reversed()

Returns a reverse-ordered view of this collection.

abstract boolean add(E e)

Adds the specified element to this set if it is not already present (optional operation).

abstract boolean addAll(Collection<? extends E> c)

Adds all of the elements in the specified collection to this set if they're not already present (optional operation).

abstract void clear()

Removes all of the elements from this set (optional operation).

abstract boolean contains(Object o)

Returns true if this set contains the specified element.

abstract boolean containsAll(Collection<?> c)

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

static <E> Set<E> copyOf(Collection<? extends E> coll)

Returns an unmodifiable Set containing the elements of the given Collection.

abstract boolean equals(Object o)

Compares the specified object with this set for equality.

abstract int hashCode()

Returns the hash code value for this set.

abstract boolean isEmpty()

Returns true if this set contains no elements.

abstract Iterator<E> iterator()

Returns an iterator over the elements in this set.

static <E> Set<E> of(E e1, E e2, E e3)

Returns an unmodifiable set containing three elements.

static <E> Set<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9)

Returns an unmodifiable set containing nine elements.

static <E> Set<E> of(E e1, E e2, E e3, E e4, E e5)

Returns an unmodifiable set containing five elements.

static <E> Set<E> of(E e1, E e2, E e3, E e4, E e5, E e6)

Returns an unmodifiable set containing six elements.

static <E> Set<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8)

Returns an unmodifiable set containing eight elements.

static <E> Set<E> of(E... elements)

Returns an unmodifiable set containing an arbitrary number of elements.

static <E> Set<E> of()

Returns an unmodifiable set containing zero elements.

static <E> Set<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10)

Returns an unmodifiable set containing ten elements.

static <E> Set<E> of(E e1, E e2)

Returns an unmodifiable set containing two elements.

static <E> Set<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7)

Returns an unmodifiable set containing seven elements.

static <E> Set<E> of(E e1, E e2, E e3, E e4)

Returns an unmodifiable set containing four elements.

static <E> Set<E> of(E e1)

Returns an unmodifiable set containing one element.

abstract boolean remove(Object o)

Removes the specified element from this set if it is present (optional operation).

abstract boolean removeAll(Collection<?> c)

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

abstract boolean retainAll(Collection<?> c)

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

abstract int size()

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

default Spliterator<E> spliterator()

Creates a Spliterator over the elements in this set.

abstract Object[] toArray()

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

abstract <T> T[] toArray(T[] a)

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

abstract boolean add(E e)

Ensures that this collection contains the specified element (optional operation).

abstract boolean addAll(Collection<? extends E> c)

Adds all of the elements in the specified collection to this collection (optional operation).

abstract void clear()

Removes all of the elements from this collection (optional operation).

abstract boolean contains(Object o)

Returns true if this collection contains the specified element.

abstract boolean containsAll(Collection<?> c)

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

abstract boolean equals(Object o)

Compares the specified object with this collection for equality.

abstract int hashCode()

Returns the hash code value for this collection.

abstract boolean isEmpty()

Returns true if this collection contains no elements.

abstract Iterator<E> iterator()

Returns an iterator over the elements in this collection.

default Stream<E> parallelStream()

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

abstract boolean remove(Object o)

Removes a single instance of the specified element from this collection, if it is present (optional operation).

abstract boolean removeAll(Collection<?> c)

Removes all of this collection's elements that are also contained in the specified collection (optional operation).

default boolean removeIf(Predicate<? super E> filter)

Removes all of the elements of this collection that satisfy the given predicate.

abstract boolean retainAll(Collection<?> c)

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

abstract int size()

Returns the number of elements in this collection.

default Spliterator<E> spliterator()

Creates a Spliterator over the elements in this collection.

default Stream<E> stream()

Returns a sequential Stream with this collection as its source.

abstract <T> T[] toArray(T[] a)

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

abstract Object[] toArray()

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

default <T> T[] toArray(IntFunction<T[]> generator)

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

default void forEach(Consumer<? super T> action)

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

abstract Iterator<E> iterator()

Returns an iterator over elements of type T.

default Spliterator<E> spliterator()

Creates a Spliterator over the elements described by this Iterable.

Public methods

reversed

Added in API level 35
public abstract SequencedSet<E> reversed ()

Returns a reverse-ordered view of this collection. The encounter order of elements in the returned view is the inverse of the encounter order of elements in this collection. The reverse ordering affects all order-sensitive operations, including those on the view collections of the returned view. If the collection implementation permits modifications to this view, the modifications "write through" to the underlying collection. Changes to the underlying collection might or might not be visible in this reversed view, depending upon the implementation.

Returns
SequencedSet<E> a reverse-ordered view of this collection, as a SequencedSet