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

# Deque


`
public


interface
Deque
`


`


implements

https://developer.android.com/reference/java/util/Queue<E>,

https://developer.android.com/reference/java/util/SequencedCollection<E>


`

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

|---|
| Known indirect subclasses [ArrayDeque](https://developer.android.com/reference/java/util/ArrayDeque)\<E\>, [BlockingDeque](https://developer.android.com/reference/java/util/concurrent/BlockingDeque)\<E\>, [ConcurrentLinkedDeque](https://developer.android.com/reference/java/util/concurrent/ConcurrentLinkedDeque)\<E\>, [LinkedBlockingDeque](https://developer.android.com/reference/java/util/concurrent/LinkedBlockingDeque)\<E\>, [LinkedList](https://developer.android.com/reference/java/util/LinkedList)\<E\> |---|---| | [ArrayDeque](https://developer.android.com/reference/java/util/ArrayDeque)\<E\> | Resizable-array implementation of the `https://developer.android.com/reference/java/util/Deque` 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. | | [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. | | [LinkedList](https://developer.android.com/reference/java/util/LinkedList)\<E\> | Doubly-linked list implementation of the `List` and `Deque` interfaces. | |

<br />

*** ** * ** ***

A linear collection that supports element insertion and removal at
both ends. The name *deque* is short for "double ended queue"
and is usually pronounced "deck". Most `Deque`
implementations place no fixed limits on the number of elements
they may contain, but this interface supports capacity-restricted
deques as well as those with no fixed size limit.

This interface defines methods to access the elements at both
ends of the deque. Methods are provided to insert, remove, and
examine the element. Each of these methods exists in two forms:
one throws an exception if the operation fails, the other returns a
special value (either `null` or `false`, depending on
the operation). The latter form of the insert operation is
designed specifically for use with capacity-restricted
`Deque` implementations; in most implementations, insert
operations cannot fail.

The twelve methods described above are summarized in the
following table:

|   | First Element (Head) || Last Element (Tail) ||
|   | Throws exception | Special value | Throws exception | Special value |
| Insert | `https://developer.android.com/reference/java/util/Deque#addFirst(E)` | `https://developer.android.com/reference/java/util/Deque#offerFirst(E)` | `https://developer.android.com/reference/java/util/Deque#addLast(E)` | `https://developer.android.com/reference/java/util/Deque#offerLast(E)` |
| Remove | `https://developer.android.com/reference/java/util/Deque#removeFirst()` | `https://developer.android.com/reference/java/util/Deque#pollFirst()` | `https://developer.android.com/reference/java/util/Deque#removeLast()` | `https://developer.android.com/reference/java/util/Deque#pollLast()` |
| Examine | `https://developer.android.com/reference/java/util/Deque#getFirst()` | `https://developer.android.com/reference/java/util/Deque#peekFirst()` | `https://developer.android.com/reference/java/util/Deque#getLast()` | `https://developer.android.com/reference/java/util/Deque#peekLast()` |
|---|---|---|---|---|
[Summary of Deque methods]

This interface extends the `https://developer.android.com/reference/java/util/Queue` interface. When a deque is
used as a queue, FIFO (First-In-First-Out) behavior results. Elements are
added at the end of the deque and removed from the beginning. The methods
inherited from the `Queue` interface are precisely equivalent to
`Deque` methods as indicated in the following table:

| `Queue` Method | Equivalent `Deque` Method |
| `https://developer.android.com/reference/java/util/Deque#add(E)` | `https://developer.android.com/reference/java/util/Deque#addLast(E)` |
| `https://developer.android.com/reference/java/util/Deque#offer(E)` | `https://developer.android.com/reference/java/util/Deque#offerLast(E)` |
| `https://developer.android.com/reference/java/util/Deque#remove()` | `https://developer.android.com/reference/java/util/Deque#removeFirst()` |
| `https://developer.android.com/reference/java/util/Deque#poll()` | `https://developer.android.com/reference/java/util/Deque#pollFirst()` |
| `https://developer.android.com/reference/java/util/Deque#element()` | `https://developer.android.com/reference/java/util/Deque#getFirst()` |
| `https://developer.android.com/reference/java/util/Deque#peek()` | `https://developer.android.com/reference/java/util/Deque#peekFirst()` |
|---|---|
[Comparison of Queue and Deque methods]

Deques can also be used as LIFO (Last-In-First-Out) stacks. This
interface should be used in preference to the legacy `https://developer.android.com/reference/java/util/Stack` class.
When a deque is used as a stack, elements are pushed and popped from the
beginning of the deque. Stack methods are equivalent to `Deque`
methods as indicated in the table below:

| Stack Method | Equivalent `Deque` Method |
| `https://developer.android.com/reference/java/util/Deque#push(E)` | `https://developer.android.com/reference/java/util/Deque#addFirst(E)` |
| `https://developer.android.com/reference/java/util/Deque#pop()` | `https://developer.android.com/reference/java/util/Deque#removeFirst()` |
| `https://developer.android.com/reference/java/util/Deque#peek()` | `https://developer.android.com/reference/java/util/Deque#peekFirst()` |
|---|---|
[Comparison of Stack and Deque methods]

Note that the `https://developer.android.com/reference/java/util/Deque#peek()` method works equally well when
a deque is used as a queue or a stack; in either case, elements are
drawn from the beginning of the deque.

This interface provides two methods to remove interior
elements, `https://developer.android.com/reference/java/util/Deque#removeFirstOccurrence(java.lang.Object)` and
`https://developer.android.com/reference/java/util/Deque#removeLastOccurrence(java.lang.Object)`.

Unlike the `https://developer.android.com/reference/java/util/List` interface, this interface does not
provide support for indexed access to elements.

While `Deque` implementations are not strictly required
to prohibit the insertion of null elements, they are strongly
encouraged to do so. Users of any `Deque` implementations
that do allow null elements are strongly encouraged *not* to
take advantage of the ability to insert nulls. This is so because
`null` is used as a special return value by various methods
to indicate that the deque is empty.

`Deque` implementations generally do not define
element-based versions of the `equals` and `hashCode`
methods, but instead inherit the identity-based versions from class
`Object`.

## Summary

| ### Public methods ||
|---|---|
| ` abstract boolean` | ` https://developer.android.com/reference/java/util/Deque#add(E)(E e) ` Inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque) if it is possible to do so immediately without violating capacity restrictions, returning `true` upon success and throwing an `IllegalStateException` if no space is currently available. |
| ` abstract boolean` | ` https://developer.android.com/reference/java/util/Deque#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 at the end of this deque, as if by calling `https://developer.android.com/reference/java/util/Deque#addLast(E)` on each one, in the order that they are returned by the collection's iterator. |
| ` abstract void` | ` https://developer.android.com/reference/java/util/Deque#addFirst(E)(E e) ` Inserts the specified element at the front of this deque if it is possible to do so immediately without violating capacity restrictions, throwing an `IllegalStateException` if no space is currently available. |
| ` abstract void` | ` https://developer.android.com/reference/java/util/Deque#addLast(E)(E e) ` Inserts the specified element at the end of this deque if it is possible to do so immediately without violating capacity restrictions, throwing an `IllegalStateException` if no space is currently available. |
| ` abstract boolean` | ` https://developer.android.com/reference/java/util/Deque#contains(java.lang.Object)(https://developer.android.com/reference/java/lang/Object o) ` Returns `true` if this deque contains the specified element. |
| ` abstract https://developer.android.com/reference/java/util/Iterator<E>` | ` https://developer.android.com/reference/java/util/Deque#descendingIterator()() ` Returns an iterator over the elements in this deque in reverse sequential order. |
| ` abstract E` | ` https://developer.android.com/reference/java/util/Deque#element()() ` Retrieves, but does not remove, the head of the queue represented by this deque (in other words, the first element of this deque). |
| ` abstract E` | ` https://developer.android.com/reference/java/util/Deque#getFirst()() ` Retrieves, but does not remove, the first element of this deque. |
| ` abstract E` | ` https://developer.android.com/reference/java/util/Deque#getLast()() ` Retrieves, but does not remove, the last element of this deque. |
| ` abstract https://developer.android.com/reference/java/util/Iterator<E>` | ` https://developer.android.com/reference/java/util/Deque#iterator()() ` Returns an iterator over the elements in this deque in proper sequence. |
| ` abstract boolean` | ` https://developer.android.com/reference/java/util/Deque#offer(E)(E e) ` Inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque) if it is possible to do so immediately without violating capacity restrictions, returning `true` upon success and `false` if no space is currently available. |
| ` abstract boolean` | ` https://developer.android.com/reference/java/util/Deque#offerFirst(E)(E e) ` Inserts the specified element at the front of this deque unless it would violate capacity restrictions. |
| ` abstract boolean` | ` https://developer.android.com/reference/java/util/Deque#offerLast(E)(E e) ` Inserts the specified element at the end of this deque unless it would violate capacity restrictions. |
| ` abstract E` | ` https://developer.android.com/reference/java/util/Deque#peek()() ` Retrieves, but does not remove, the head of the queue represented by this deque (in other words, the first element of this deque), or returns `null` if this deque is empty. |
| ` abstract E` | ` https://developer.android.com/reference/java/util/Deque#peekFirst()() ` Retrieves, but does not remove, the first element of this deque, or returns `null` if this deque is empty. |
| ` abstract E` | ` https://developer.android.com/reference/java/util/Deque#peekLast()() ` Retrieves, but does not remove, the last element of this deque, or returns `null` if this deque is empty. |
| ` abstract E` | ` https://developer.android.com/reference/java/util/Deque#poll()() ` Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque), or returns `null` if this deque is empty. |
| ` abstract E` | ` https://developer.android.com/reference/java/util/Deque#pollFirst()() ` Retrieves and removes the first element of this deque, or returns `null` if this deque is empty. |
| ` abstract E` | ` https://developer.android.com/reference/java/util/Deque#pollLast()() ` Retrieves and removes the last element of this deque, or returns `null` if this deque is empty. |
| ` abstract E` | ` https://developer.android.com/reference/java/util/Deque#pop()() ` Pops an element from the stack represented by this deque. |
| ` abstract void` | ` https://developer.android.com/reference/java/util/Deque#push(E)(E e) ` Pushes an element onto the stack represented by this deque (in other words, at the head of this deque) if it is possible to do so immediately without violating capacity restrictions, throwing an `IllegalStateException` if no space is currently available. |
| ` abstract E` | ` https://developer.android.com/reference/java/util/Deque#remove()() ` Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque). |
| ` abstract boolean` | ` https://developer.android.com/reference/java/util/Deque#remove(java.lang.Object)(https://developer.android.com/reference/java/lang/Object o) ` Removes the first occurrence of the specified element from this deque. |
| ` abstract E` | ` https://developer.android.com/reference/java/util/Deque#removeFirst()() ` Retrieves and removes the first element of this deque. |
| ` abstract boolean` | ` https://developer.android.com/reference/java/util/Deque#removeFirstOccurrence(java.lang.Object)(https://developer.android.com/reference/java/lang/Object o) ` Removes the first occurrence of the specified element from this deque. |
| ` abstract E` | ` https://developer.android.com/reference/java/util/Deque#removeLast()() ` Retrieves and removes the last element of this deque. |
| ` abstract boolean` | ` https://developer.android.com/reference/java/util/Deque#removeLastOccurrence(java.lang.Object)(https://developer.android.com/reference/java/lang/Object o) ` Removes the last occurrence of the specified element from this deque. |
| ` default https://developer.android.com/reference/java/util/Deque<E>` | ` https://developer.android.com/reference/java/util/Deque#reversed()() ` Returns a reverse-ordered [view](https://developer.android.com/reference/java/util/Collection#view) of this collection. |
| ` abstract int` | ` https://developer.android.com/reference/java/util/Deque#size()() ` Returns the number of elements in this deque. |

| ### Inherited methods |
|---|---|
| From interface ` https://developer.android.com/reference/java/util/Queue ` |---|---| | ` abstract boolean` | ` https://developer.android.com/reference/java/util/Queue#add(E)(E e) ` Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning `true` upon success and throwing an `IllegalStateException` if no space is currently available. | | ` abstract E` | ` https://developer.android.com/reference/java/util/Queue#element()() ` Retrieves, but does not remove, the head of this queue. | | ` abstract boolean` | ` https://developer.android.com/reference/java/util/Queue#offer(E)(E e) ` Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions. | | ` abstract E` | ` https://developer.android.com/reference/java/util/Queue#peek()() ` Retrieves, but does not remove, the head of this queue, or returns `null` if this queue is empty. | | ` abstract E` | ` https://developer.android.com/reference/java/util/Queue#poll()() ` Retrieves and removes the head of this queue, or returns `null` if this queue is empty. | | ` abstract E` | ` https://developer.android.com/reference/java/util/Queue#remove()() ` Retrieves and removes the head of this queue. | ||
| From interface ` https://developer.android.com/reference/java/util/SequencedCollection ` |---|---| | ` 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. | ||
| 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

### add

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

```
public abstract boolean add (E e)
```

Inserts the specified element into the queue represented by this deque
(in other words, at the tail of this deque) if it is possible to do so
immediately without violating capacity restrictions, returning
`true` upon success and throwing an
`IllegalStateException` if no space is currently available.
When using a capacity-restricted deque, it is generally preferable to
use `https://developer.android.com/reference/java/util/Deque#offer(E)`.

This method is equivalent to `https://developer.android.com/reference/java/util/Deque#addLast(E)`.

<br />

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

| Returns ||
|---|---|
| `boolean` | `true` (as specified by `https://developer.android.com/reference/java/util/Collection#add(E)`) <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ClassCastException` | if the class of the specified element prevents it from being added to this deque |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if some property of the specified element prevents it from being added to this deque |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if the element cannot be added at this time due to capacity restrictions |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if the specified element is null and this deque does not permit null elements |

### addAll

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

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

Adds all of the elements in the specified collection at the end
of this deque, as if by calling `https://developer.android.com/reference/java/util/Deque#addLast(E)` on each one,
in the order that they are returned by the collection's iterator.

When using a capacity-restricted deque, it is generally preferable
to call `https://developer.android.com/reference/java/util/Deque#offer(E)` separately on each element.

An exception encountered while trying to add an element may result
in only some of the elements having been successfully added when
the associated exception is thrown.

<br />

| Parameters ||
|---|---|
| `c` | `Collection`: the elements to be inserted into this deque <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if this deque changed as a result of the call <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ClassCastException` | if the class of an element of the specified collection prevents it from being added to this deque |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if some property of an element of the specified collection prevents it from being added to this deque |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if not all the elements can be added at this time due to insertion restrictions |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if the specified collection contains a null element and this deque does not permit null elements, or if the specified collection is null |

### addFirst

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

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

Inserts the specified element at the front of this deque if it is
possible to do so immediately without violating capacity restrictions,
throwing an `IllegalStateException` if no space is currently
available. When using a capacity-restricted deque, it is generally
preferable to use method `https://developer.android.com/reference/java/util/Deque#offerFirst(E)`.

<br />

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

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ClassCastException` | if the class of the specified element prevents it from being added to this deque |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if some property of the specified element prevents it from being added to this deque |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if the element cannot be added at this time due to capacity restrictions |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if the specified element is null and this deque does not permit null elements |

### addLast

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

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

Inserts the specified element at the end of this deque if it is
possible to do so immediately without violating capacity restrictions,
throwing an `IllegalStateException` if no space is currently
available. When using a capacity-restricted deque, it is generally
preferable to use method `https://developer.android.com/reference/java/util/Deque#offerLast(E)`.

This method is equivalent to `https://developer.android.com/reference/java/util/Deque#add(E)`.

<br />

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

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ClassCastException` | if the class of the specified element prevents it from being added to this deque |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if some property of the specified element prevents it from being added to this deque |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if the element cannot be added at this time due to capacity restrictions |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if the specified element is null and this deque does not permit null elements |

### contains

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

```
public abstract boolean contains (Object o)
```

Returns `true` if this deque contains the specified element.
More formally, returns `true` if and only if this deque contains
at least one element `e` such that `Objects.equals(o, e)`.

<br />

| Parameters ||
|---|---|
| `o` | `Object`: element whose presence in this deque is to be tested <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if this deque contains the specified element <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ClassCastException` | if the class of the specified element is incompatible with this deque ([ERROR(optional/java.util.Collection##optional-restrictions optional)](https://developer.android.com/)) |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if the specified element is null and this deque does not permit null elements ([ERROR(optional/java.util.Collection##optional-restrictions optional)](https://developer.android.com/)) |

### descendingIterator

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

```
public abstract Iterator<E> descendingIterator ()
```

Returns an iterator over the elements in this deque in reverse
sequential order. The elements will be returned in order from
last (tail) to first (head).

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/Iterator<E>` | an iterator over the elements in this deque in reverse sequence <br /> |

### element

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

```
public abstract E element ()
```

Retrieves, but does not remove, the head of the queue represented by
this deque (in other words, the first element of this deque).
This method differs from `https://developer.android.com/reference/java/util/Deque#peek()` only in that it throws an
exception if this deque is empty.

This method is equivalent to `https://developer.android.com/reference/java/util/Deque#getFirst()`.

<br />

| Returns ||
|---|---|
| `E` | the head of the queue represented by this deque <br /> |

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

### getFirst

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

```
public abstract E getFirst ()
```

Retrieves, but does not remove, the first element of this deque.

This method differs from `https://developer.android.com/reference/java/util/Deque#peekFirst()` only in that it
throws an exception if this deque is empty.

<br />

| Returns ||
|---|---|
| `E` | the head of this deque <br /> |

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

### getLast

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

```
public abstract E getLast ()
```

Retrieves, but does not remove, the last element of this deque.
This method differs from `https://developer.android.com/reference/java/util/Deque#peekLast()` only in that it
throws an exception if this deque is empty.

<br />

| Returns ||
|---|---|
| `E` | the tail of this deque <br /> |

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

### iterator

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

```
public abstract Iterator<E> iterator ()
```

Returns an iterator over the elements in this deque in proper sequence.
The elements will be returned in order from first (head) to last (tail).

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/Iterator<E>` | an iterator over the elements in this deque in proper sequence <br /> |

### offer

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

```
public abstract boolean offer (E e)
```

Inserts the specified element into the queue represented by this deque
(in other words, at the tail of this deque) if it is possible to do so
immediately without violating capacity restrictions, returning
`true` upon success and `false` if no space is currently
available. When using a capacity-restricted deque, this method is
generally preferable to the `https://developer.android.com/reference/java/util/Deque#add(E)` method, which can fail to
insert an element only by throwing an exception.

This method is equivalent to `https://developer.android.com/reference/java/util/Deque#offerLast(E)`.

<br />

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

| Returns ||
|---|---|
| `boolean` | `true` if the element was added to this deque, else `false` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ClassCastException` | if the class of the specified element prevents it from being added to this deque |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if some property of the specified element prevents it from being added to this deque |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if the specified element is null and this deque does not permit null elements |

### offerFirst

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

```
public abstract boolean offerFirst (E e)
```

Inserts the specified element at the front of this deque unless it would
violate capacity restrictions. When using a capacity-restricted deque,
this method is generally preferable to the `https://developer.android.com/reference/java/util/Deque#addFirst(E)` method,
which can fail to insert an element only by throwing an exception.

<br />

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

| Returns ||
|---|---|
| `boolean` | `true` if the element was added to this deque, else `false` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ClassCastException` | if the class of the specified element prevents it from being added to this deque |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if some property of the specified element prevents it from being added to this deque |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if the specified element is null and this deque does not permit null elements |

### offerLast

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

```
public abstract boolean offerLast (E e)
```

Inserts the specified element at the end of this deque unless it would
violate capacity restrictions. When using a capacity-restricted deque,
this method is generally preferable to the `https://developer.android.com/reference/java/util/Deque#addLast(E)` method,
which can fail to insert an element only by throwing an exception.

<br />

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

| Returns ||
|---|---|
| `boolean` | `true` if the element was added to this deque, else `false` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ClassCastException` | if the class of the specified element prevents it from being added to this deque |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if some property of the specified element prevents it from being added to this deque |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if the specified element is null and this deque does not permit null elements |

### peek

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

```
public abstract E peek ()
```

Retrieves, but does not remove, the head of the queue represented by
this deque (in other words, the first element of this deque), or
returns `null` if this deque is empty.

This method is equivalent to `https://developer.android.com/reference/java/util/Deque#peekFirst()`.

<br />

| Returns ||
|---|---|
| `E` | the head of the queue represented by this deque, or `null` if this deque is empty <br /> |

### peekFirst

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

```
public abstract E peekFirst ()
```

Retrieves, but does not remove, the first element of this deque,
or returns `null` if this deque is empty.

<br />

| Returns ||
|---|---|
| `E` | the head of this deque, or `null` if this deque is empty <br /> |

### peekLast

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

```
public abstract E peekLast ()
```

Retrieves, but does not remove, the last element of this deque,
or returns `null` if this deque is empty.

<br />

| Returns ||
|---|---|
| `E` | the tail of this deque, or `null` if this deque is empty <br /> |

### poll

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

```
public abstract E poll ()
```

Retrieves and removes the head of the queue represented by this deque
(in other words, the first element of this deque), or returns
`null` if this deque is empty.

This method is equivalent to `https://developer.android.com/reference/java/util/Deque#pollFirst()`.

<br />

| Returns ||
|---|---|
| `E` | the first element of this deque, or `null` if this deque is empty <br /> |

### pollFirst

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

```
public abstract E pollFirst ()
```

Retrieves and removes the first element of this deque,
or returns `null` if this deque is empty.

<br />

| Returns ||
|---|---|
| `E` | the head of this deque, or `null` if this deque is empty <br /> |

### pollLast

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

```
public abstract E pollLast ()
```

Retrieves and removes the last element of this deque,
or returns `null` if this deque is empty.

<br />

| Returns ||
|---|---|
| `E` | the tail of this deque, or `null` if this deque is empty <br /> |

### pop

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

```
public abstract E pop ()
```

Pops an element from the stack represented by this deque. In other
words, removes and returns the first element of this deque.

This method is equivalent to `https://developer.android.com/reference/java/util/Deque#removeFirst()`.

<br />

| Returns ||
|---|---|
| `E` | the element at the front of this deque (which is the top of the stack represented by this deque) <br /> |

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

### push

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

```
public abstract void push (E e)
```

Pushes an element onto the stack represented by this deque (in other
words, at the head of this deque) if it is possible to do so
immediately without violating capacity restrictions, throwing an
`IllegalStateException` if no space is currently available.

This method is equivalent to `https://developer.android.com/reference/java/util/Deque#addFirst(E)`.

<br />

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

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ClassCastException` | if the class of the specified element prevents it from being added to this deque |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if some property of the specified element prevents it from being added to this deque |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if the element cannot be added at this time due to capacity restrictions |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if the specified element is null and this deque does not permit null elements |

### remove

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

```
public abstract E remove ()
```

Retrieves and removes the head of the queue represented by this deque
(in other words, the first element of this deque).
This method differs from `https://developer.android.com/reference/java/util/Deque#poll()` only in that it
throws an exception if this deque is empty.

This method is equivalent to `https://developer.android.com/reference/java/util/Deque#removeFirst()`.

<br />

| Returns ||
|---|---|
| `E` | the head of the queue represented by this deque <br /> |

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

### remove

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

```
public abstract boolean remove (Object o)
```

Removes the first occurrence of the specified element from this deque.
If the deque does not contain the element, it is unchanged.
More formally, removes the first element `e` such that
`Objects.equals(o, e)` (if such an element exists).
Returns `true` if this deque contained the specified element
(or equivalently, if this deque changed as a result of the call).

This method is equivalent to `https://developer.android.com/reference/java/util/Deque#removeFirstOccurrence(java.lang.Object)`.

<br />

| Parameters ||
|---|---|
| `o` | `Object`: element to be removed from this deque, if present <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if an element was removed as a result of this call <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ClassCastException` | if the class of the specified element is incompatible with this deque ([ERROR(optional/java.util.Collection##optional-restrictions optional)](https://developer.android.com/)) |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if the specified element is null and this deque does not permit null elements ([ERROR(optional/java.util.Collection##optional-restrictions optional)](https://developer.android.com/)) |

### removeFirst

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

```
public abstract E removeFirst ()
```

Retrieves and removes the first element of this deque. This method
differs from `https://developer.android.com/reference/java/util/Deque#pollFirst()` only in that it throws an
exception if this deque is empty.

<br />

| Returns ||
|---|---|
| `E` | the head of this deque <br /> |

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

### removeFirstOccurrence

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

```
public abstract boolean removeFirstOccurrence (Object o)
```

Removes the first occurrence of the specified element from this deque.
If the deque does not contain the element, it is unchanged.
More formally, removes the first element `e` such that
`Objects.equals(o, e)` (if such an element exists).
Returns `true` if this deque contained the specified element
(or equivalently, if this deque changed as a result of the call).

<br />

| Parameters ||
|---|---|
| `o` | `Object`: element to be removed from this deque, if present <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if an element was removed as a result of this call <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ClassCastException` | if the class of the specified element is incompatible with this deque ([ERROR(optional/java.util.Collection##optional-restrictions optional)](https://developer.android.com/)) |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if the specified element is null and this deque does not permit null elements ([ERROR(optional/java.util.Collection##optional-restrictions optional)](https://developer.android.com/)) |

### removeLast

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

```
public abstract E removeLast ()
```

Retrieves and removes the last element of this deque. This method
differs from `https://developer.android.com/reference/java/util/Deque#pollLast()` only in that it throws an
exception if this deque is empty.

<br />

| Returns ||
|---|---|
| `E` | the tail of this deque <br /> |

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

### removeLastOccurrence

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

```
public abstract boolean removeLastOccurrence (Object o)
```

Removes the last occurrence of the specified element from this deque.
If the deque does not contain the element, it is unchanged.
More formally, removes the last element `e` such that
`Objects.equals(o, e)` (if such an element exists).
Returns `true` if this deque contained the specified element
(or equivalently, if this deque changed as a result of the call).

<br />

| Parameters ||
|---|---|
| `o` | `Object`: element to be removed from this deque, if present <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if an element was removed as a result of this call <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ClassCastException` | if the class of the specified element is incompatible with this deque ([ERROR(optional/java.util.Collection##optional-restrictions optional)](https://developer.android.com/)) |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if the specified element is null and this deque does not permit null elements ([ERROR(optional/java.util.Collection##optional-restrictions optional)](https://developer.android.com/)) |

### reversed

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

```
public Deque<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 />

##### Implementation Requirements:

- The implementation in this interface returns a reverse-ordered Deque view. The `reversed()` method of the view returns a reference to this Deque. Other operations on the view are implemented via calls to public methods on this Deque. The exact relationship between calls on the view and calls on this Deque is unspecified. However, order-sensitive operations generally behave as if they delegate to the appropriate method with the opposite orientation. For example, calling `getFirst` on the view might result in a call to `getLast` on this Deque.

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

### size

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

```
public abstract int size ()
```

Returns the number of elements in this deque.

<br />

| Returns ||
|---|---|
| `int` | the number of elements in this deque <br /> |