Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Methods](https://developer.android.com/reference/java/util/SequencedCollection#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/java/util/SequencedCollection#inhmethods)

# SequencedCollection

` public interface SequencedCollection `   
` implements https://developer.android.com/reference/java/util/Collection<E> `

|---|
| java.util.SequencedCollection\<E\> |

Known indirect subclasses [AbstractList](https://developer.android.com/reference/java/util/AbstractList)\<E\>, [AbstractSequentialList](https://developer.android.com/reference/java/util/AbstractSequentialList)\<E\>, [ArrayDeque](https://developer.android.com/reference/java/util/ArrayDeque)\<E\>, [ArrayList](https://developer.android.com/reference/java/util/ArrayList)\<E\>, [BlockingDeque](https://developer.android.com/reference/java/util/concurrent/BlockingDeque)\<E\>, [ConcurrentLinkedDeque](https://developer.android.com/reference/java/util/concurrent/ConcurrentLinkedDeque)\<E\>, [ConcurrentSkipListSet](https://developer.android.com/reference/java/util/concurrent/ConcurrentSkipListSet)\<E\>, [CopyOnWriteArrayList](https://developer.android.com/reference/java/util/concurrent/CopyOnWriteArrayList)\<E\>, [Deque](https://developer.android.com/reference/java/util/Deque)\<E\>, [LinkedBlockingDeque](https://developer.android.com/reference/java/util/concurrent/LinkedBlockingDeque)\<E\>, [LinkedHashSet](https://developer.android.com/reference/java/util/LinkedHashSet)\<E\>, [LinkedList](https://developer.android.com/reference/java/util/LinkedList)\<E\>, [List](https://developer.android.com/reference/java/util/List)\<E\>, [NavigableSet](https://developer.android.com/reference/java/util/NavigableSet)\<E\>, [SequencedSet](https://developer.android.com/reference/java/util/SequencedSet)\<E\>, [SortedSet](https://developer.android.com/reference/java/util/SortedSet)\<E\>, [Stack](https://developer.android.com/reference/java/util/Stack)\<E\>, [TreeSet](https://developer.android.com/reference/java/util/TreeSet)\<E\>, [Vector](https://developer.android.com/reference/java/util/Vector)\<E\> [AbstractList](https://developer.android.com/reference/java/util/AbstractList)\<E\> This class provides a skeletal implementation of the `https://developer.android.com/reference/java/util/List` interface to minimize the effort required to implement this interface backed by a "random access" data store (such as an array). [AbstractSequentialList](https://developer.android.com/reference/java/util/AbstractSequentialList)\<E\> This class provides a skeletal implementation of the `List` interface to minimize the effort required to implement this interface backed by a "sequential access" data store (such as a linked list). [ArrayDeque](https://developer.android.com/reference/java/util/ArrayDeque)\<E\> Resizable-array implementation of the `https://developer.android.com/reference/java/util/Deque` interface. [ArrayList](https://developer.android.com/reference/java/util/ArrayList)\<E\> Resizable-array implementation of the `List` interface. [BlockingDeque](https://developer.android.com/reference/java/util/concurrent/BlockingDeque)\<E\> A `https://developer.android.com/reference/java/util/Deque` that additionally supports blocking operations that wait for the deque to become non-empty when retrieving an element, and wait for space to become available in the deque when storing an element. [ConcurrentLinkedDeque](https://developer.android.com/reference/java/util/concurrent/ConcurrentLinkedDeque)\<E\> An unbounded concurrent [deque](https://developer.android.com/reference/java/util/Deque) based on linked nodes. [ConcurrentSkipListSet](https://developer.android.com/reference/java/util/concurrent/ConcurrentSkipListSet)\<E\> A scalable concurrent `https://developer.android.com/reference/java/util/NavigableSet` implementation based on a `https://developer.android.com/reference/java/util/concurrent/ConcurrentSkipListMap`. [CopyOnWriteArrayList](https://developer.android.com/reference/java/util/concurrent/CopyOnWriteArrayList)\<E\> A thread-safe variant of `https://developer.android.com/reference/java/util/ArrayList` in which all mutative operations (`add`, `set`, and so on) are implemented by making a fresh copy of the underlying array. [Deque](https://developer.android.com/reference/java/util/Deque)\<E\> A linear collection that supports element insertion and removal at both ends. [LinkedBlockingDeque](https://developer.android.com/reference/java/util/concurrent/LinkedBlockingDeque)\<E\> An optionally-bounded [blocking deque](https://developer.android.com/reference/java/util/concurrent/BlockingDeque) based on linked nodes. [LinkedHashSet](https://developer.android.com/reference/java/util/LinkedHashSet)\<E\> Hash table and linked list implementation of the `Set` interface, with well-defined encounter order.
[LinkedList](https://developer.android.com/reference/java/util/LinkedList)\<E\> Doubly-linked list implementation of the `List` and `Deque` interfaces. [List](https://developer.android.com/reference/java/util/List)\<E\> An ordered collection, where the user has precise control over where in the list each element is inserted. [NavigableSet](https://developer.android.com/reference/java/util/NavigableSet)\<E\> A `https://developer.android.com/reference/java/util/SortedSet` extended with navigation methods reporting closest matches for given search targets. [SequencedSet](https://developer.android.com/reference/java/util/SequencedSet)\<E\> A collection that is both a `https://developer.android.com/reference/java/util/SequencedCollection` and a `https://developer.android.com/reference/java/util/Set`. [SortedSet](https://developer.android.com/reference/java/util/SortedSet)\<E\> A `https://developer.android.com/reference/java/util/Set` that further provides a *total ordering* on its elements. [Stack](https://developer.android.com/reference/java/util/Stack)\<E\> The `Stack` class represents a last-in-first-out (LIFO) stack of objects. [TreeSet](https://developer.android.com/reference/java/util/TreeSet)\<E\> A `https://developer.android.com/reference/java/util/NavigableSet` implementation based on a `https://developer.android.com/reference/java/util/TreeMap`. [Vector](https://developer.android.com/reference/java/util/Vector)\<E\> The `Vector` class implements a growable array of objects.   

*** ** * ** ***

A collection that has a well-defined encounter order, that supports operations at both ends, and that is reversible. The elements of a sequenced collection have an *encounter order*, where conceptually the elements have a linear arrangement from the first element to the last element. Given any two elements, one element is either before (closer to the first element) or after (closer to the last element) the other element.

(Note that this definition does not imply anything about physical positioning of elements, such as their locations in a computer's memory.)

Several methods inherited from the `https://developer.android.com/reference/java/util/Collection` interface are required to operate on elements according to this collection's encounter order. For instance, the `https://developer.android.com/reference/java/util/Collection#iterator()` method provides elements starting from the first element, proceeding through successive elements, until the last element. Other methods that are required to operate on elements in encounter order include the following: `https://developer.android.com/reference/java/lang/Iterable#forEach(java.util.function.Consumer<?%20super%20T>)`, `https://developer.android.com/reference/java/util/Collection#parallelStream()`, `https://developer.android.com/reference/java/util/Collection#spliterator()`, `https://developer.android.com/reference/java/util/Collection#stream()`, and all overloads of the `https://developer.android.com/reference/java/util/Collection#toArray()` method.

This interface provides methods to add, retrieve, and remove elements at either end of the collection.

This interface also defines the `https://developer.android.com/reference/java/util/SequencedCollection#reversed()` method, which provides a reverse-ordered [view](https://developer.android.com/reference/java/util/Collection#view) of this collection. In the reverse-ordered view, the concepts of first and last are inverted, as are the concepts of successor and predecessor. The first element of this collection is the last element of the reverse-ordered view, and vice-versa. The successor of some element in this collection is its predecessor in the reversed view, and vice-versa. All methods that respect the encounter order of the collection operate as if the encounter order is inverted. For instance, the `https://developer.android.com/reference/java/util/Collection#iterator()` method of the reversed view reports the elements in order from the last element of this collection to the first. The availability of the `reversed` method, and its impact on the ordering semantics of all applicable methods, allow convenient iteration, searching, copying, and streaming of the elements of this collection in either forward order or reverse order.

This class is a member of the [Java Collections Framework](https://reference/java/util/package-summary.html#CollectionsFramework).

## Summary

| ### Public methods ||
|---|---|
| ` default void` | ` https://developer.android.com/reference/java/util/SequencedCollection#addFirst(E)(E e) ` Adds an element as the first element of this collection (optional operation). |
| ` default void` | ` https://developer.android.com/reference/java/util/SequencedCollection#addLast(E)(E e) ` Adds an element as the last element of this collection (optional operation). |
| ` default E` | ` https://developer.android.com/reference/java/util/SequencedCollection#getFirst()() ` Gets the first element of this collection. |
| ` default E` | ` https://developer.android.com/reference/java/util/SequencedCollection#getLast()() ` Gets the last element of this collection. |
| ` default E` | ` https://developer.android.com/reference/java/util/SequencedCollection#removeFirst()() ` Removes and returns the first element of this collection (optional operation). |
| ` default E` | ` https://developer.android.com/reference/java/util/SequencedCollection#removeLast()() ` Removes and returns the last element of this collection (optional operation). |
| ` abstract https://developer.android.com/reference/java/util/SequencedCollection<E>` | ` https://developer.android.com/reference/java/util/SequencedCollection#reversed()() ` Returns a reverse-ordered [view](https://developer.android.com/reference/java/util/Collection#view) of this collection. |

### Inherited methods

From interface ` https://developer.android.com/reference/java/util/Collection ` ` abstract boolean` ` https://developer.android.com/reference/java/util/Collection#add(E)(E e) `

Ensures that this collection contains the specified element (optional operation).
` abstract boolean` ` https://developer.android.com/reference/java/util/Collection#addAll(java.util.Collection<?%20extends%20E>)(https://developer.android.com/reference/java/util/Collection<? extends E> c) `

Adds all of the elements in the specified collection to this collection (optional operation).
` abstract void` ` https://developer.android.com/reference/java/util/Collection#clear()() `

Removes all of the elements from this collection (optional operation).
` abstract boolean` ` https://developer.android.com/reference/java/util/Collection#contains(java.lang.Object)(https://developer.android.com/reference/java/lang/Object o) `

Returns `true` if this collection contains the specified element.
` abstract boolean` ` https://developer.android.com/reference/java/util/Collection#containsAll(java.util.Collection<?>)(https://developer.android.com/reference/java/util/Collection<?> c) `

Returns `true` if this collection contains all of the elements in the specified collection.
` abstract boolean` ` https://developer.android.com/reference/java/util/Collection#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object o) `

Compares the specified object with this collection for equality.
` abstract int` ` https://developer.android.com/reference/java/util/Collection#hashCode()() `

Returns the hash code value for this collection.
` abstract boolean` ` https://developer.android.com/reference/java/util/Collection#isEmpty()() `

Returns `true` if this collection contains no elements.
` abstract https://developer.android.com/reference/java/util/Iterator<E>` ` https://developer.android.com/reference/java/util/Collection#iterator()() `

Returns an iterator over the elements in this collection.
` default https://developer.android.com/reference/java/util/stream/Stream<E>` ` https://developer.android.com/reference/java/util/Collection#parallelStream()() `

Returns a possibly parallel `Stream` with this collection as its source.
` abstract boolean` ` https://developer.android.com/reference/java/util/Collection#remove(java.lang.Object)(https://developer.android.com/reference/java/lang/Object o) `

Removes a single instance of the specified element from this collection, if it is present (optional operation).
` abstract boolean` ` https://developer.android.com/reference/java/util/Collection#removeAll(java.util.Collection<?>)(https://developer.android.com/reference/java/util/Collection<?> c) `

Removes all of this collection's elements that are also contained in the specified collection (optional operation).
` default boolean` ` https://developer.android.com/reference/java/util/Collection#removeIf(java.util.function.Predicate<?%20super%20E>)(https://developer.android.com/reference/java/util/function/Predicate<? super E> filter) `

Removes all of the elements of this collection that satisfy the given predicate (optional operation).
` abstract boolean` ` https://developer.android.com/reference/java/util/Collection#retainAll(java.util.Collection<?>)(https://developer.android.com/reference/java/util/Collection<?> c) `

Retains only the elements in this collection that are contained in the specified collection (optional operation).
` abstract int` ` https://developer.android.com/reference/java/util/Collection#size()() `

Returns the number of elements in this collection.
` default https://developer.android.com/reference/java/util/Spliterator<E>` ` https://developer.android.com/reference/java/util/Collection#spliterator()() `

Creates a `https://developer.android.com/reference/java/util/Spliterator` over the elements in this collection.
` default https://developer.android.com/reference/java/util/stream/Stream<E>` ` https://developer.android.com/reference/java/util/Collection#stream()() `

Returns a sequential `Stream` with this collection as its source.
` abstract <T> T[]` ` https://developer.android.com/reference/java/util/Collection#toArray(T[])(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 https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/util/Collection#toArray()() `

Returns an array containing all of the elements in this collection.
` default <T> T[]` ` https://developer.android.com/reference/java/util/Collection#toArray(java.util.function.IntFunction<T[]>)(https://developer.android.com/reference/java/util/function/IntFunction<T[]> generator) `

Returns an array containing all of the elements in this collection, using the provided `generator` function to allocate the returned array.
From interface ` https://developer.android.com/reference/java/lang/Iterable ` ` default void` ` https://developer.android.com/reference/java/lang/Iterable#forEach(java.util.function.Consumer<?%20super%20T>)(https://developer.android.com/reference/java/util/function/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 https://developer.android.com/reference/java/util/Iterator<E>` ` https://developer.android.com/reference/java/lang/Iterable#iterator()() `

Returns an iterator over elements of type `T`.
` default https://developer.android.com/reference/java/util/Spliterator<E>` ` https://developer.android.com/reference/java/lang/Iterable#spliterator()() `

Creates a `https://developer.android.com/reference/java/util/Spliterator` over the elements described by this `Iterable`.

## Public methods

### addFirst

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void addFirst (E e)
```

Adds an element as the first element of this collection (optional operation). After this operation completes normally, the given element will be a member of this collection, and it will be the first element in encounter order.

<br />

##### Implementation Requirements:

- The implementation in this interface always throws `UnsupportedOperationException`.

| Parameters ||
|---|---|
| `e` | `E`: the element to be added <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException` | if the specified element is null and this collection does not permit null elements |
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException` | if this collection implementation does not support this operation |

### addLast

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void addLast (E e)
```

Adds an element as the last element of this collection (optional operation). After this operation completes normally, the given element will be a member of this collection, and it will be the last element in encounter order.

<br />

##### Implementation Requirements:

- The implementation in this interface always throws `UnsupportedOperationException`.

| Parameters ||
|---|---|
| `e` | `E`: the element to be added. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException` | if the specified element is null and this collection does not permit null elements |
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException` | if this collection implementation does not support this operation |

### getFirst

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public E getFirst ()
```

Gets the first element of this collection.

<br />

##### Implementation Requirements:

- The implementation in this interface obtains an iterator of this collection, and then it obtains an element by calling the iterator's `next` method. Any `NoSuchElementException` thrown is propagated. Otherwise, it returns the element.

| Returns ||
|---|---|
| `E` | the retrieved element <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/util/NoSuchElementException` | if this collection is empty |

### getLast

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public E getLast ()
```

Gets the last element of this collection.

<br />

##### Implementation Requirements:

- The implementation in this interface obtains an iterator of the reversed view of this collection, and then it obtains an element by calling the iterator's `next` method. Any `NoSuchElementException` thrown is propagated. Otherwise, it returns the element.

| Returns ||
|---|---|
| `E` | the retrieved element <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/util/NoSuchElementException` | if this collection is empty |

### removeFirst

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public E removeFirst ()
```

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

<br />

##### Implementation Requirements:

- The implementation in this interface obtains an iterator of this collection, and then it obtains an element by calling the iterator's `next` method. Any `NoSuchElementException` thrown is propagated. It then calls the iterator's `remove` method. Any `UnsupportedOperationException` thrown is propagated. Then, it returns the element.

| Returns ||
|---|---|
| `E` | the removed element <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException` | if this collection implementation does not support this operation |
| `https://developer.android.com/reference/java/util/NoSuchElementException` | if this collection is empty |

### removeLast

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public E removeLast ()
```

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

<br />

##### Implementation Requirements:

- The implementation in this interface obtains an iterator of the reversed view of this collection, and then it obtains an element by calling the iterator's `next` method. Any `NoSuchElementException` thrown is propagated. It then calls the iterator's `remove` method. Any `UnsupportedOperationException` thrown is propagated. Then, it returns the element.

| Returns ||
|---|---|
| `E` | the removed element <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException` | if this collection implementation does not support this operation |
| `https://developer.android.com/reference/java/util/NoSuchElementException` | if this collection is empty |

### reversed

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract SequencedCollection<E> reversed ()
```

Returns a reverse-ordered [view](https://developer.android.com/reference/java/util/Collection#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.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/SequencedCollection<E>` | a reverse-ordered view of this collection <br /> |