ArrayDeque (Java SE 10 & JDK 10 ) (original) (raw)
Constructor Detail
* #### ArrayDeque
public ArrayDeque()
Constructs an empty array deque with an initial capacity sufficient to hold 16 elements.
* #### ArrayDeque
public ArrayDeque(int numElements)
Constructs an empty array deque with an initial capacity sufficient to hold the specified number of elements.
Parameters:
`numElements` \- lower bound on initial capacity of the deque
* #### ArrayDeque
public ArrayDeque([Collection](../../java/util/Collection.html "interface in java.util")<? extends [E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")> c)
Constructs a deque containing the elements of the specified collection, in the order they are returned by the collection's iterator. (The first element returned by the collection's iterator becomes the first element, or _front_ of the deque.)
Parameters:
`c` \- the collection whose elements are to be placed into the deque
Throws:
`[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if the specified collection is null
Method Detail
* #### addFirst
public void addFirst([E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque") e)
Inserts the specified element at the front of this deque.
Specified by:
`[addFirst](../../java/util/Deque.html#addFirst%28E%29)` in interface `[Deque](../../java/util/Deque.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Parameters:
`e` \- the element to add
Throws:
`[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if the specified element is null
* #### addLast
public void addLast([E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque") e)
Inserts the specified element at the end of this deque.
This method is equivalent to [add(E)](../../java/util/ArrayDeque.html#add%28E%29).
Specified by:
`[addLast](../../java/util/Deque.html#addLast%28E%29)` in interface `[Deque](../../java/util/Deque.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Parameters:
`e` \- the element to add
Throws:
`[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if the specified element is null
* #### addAll
public boolean addAll([Collection](../../java/util/Collection.html "interface in java.util")<? extends [E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")> c)
Adds all of the elements in the specified collection at the end of this deque, as if by calling [addLast(E)](../../java/util/ArrayDeque.html#addLast%28E%29) on each one, in the order that they are returned by the collection's iterator.
Specified by:
`[addAll](../../java/util/Collection.html#addAll%28java.util.Collection%29)` in interface `[Collection](../../java/util/Collection.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Specified by:
`[addAll](../../java/util/Deque.html#addAll%28java.util.Collection%29)` in interface `[Deque](../../java/util/Deque.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Overrides:
`[addAll](../../java/util/AbstractCollection.html#addAll%28java.util.Collection%29)` in class `[AbstractCollection](../../java/util/AbstractCollection.html "class in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Parameters:
`c` \- the elements to be inserted into this deque
Returns:
`true` if this deque changed as a result of the call
Throws:
`[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if the specified collection or any of its elements are null
See Also:
[AbstractCollection.add(Object)](../../java/util/AbstractCollection.html#add%28E%29)
* #### offerFirst
public boolean offerFirst([E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque") e)
Inserts the specified element at the front of this deque.
Specified by:
`[offerFirst](../../java/util/Deque.html#offerFirst%28E%29)` in interface `[Deque](../../java/util/Deque.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Parameters:
`e` \- the element to add
Returns:
`true` (as specified by [Deque.offerFirst(E)](../../java/util/Deque.html#offerFirst%28E%29))
Throws:
`[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if the specified element is null
* #### offerLast
public boolean offerLast([E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque") e)
Inserts the specified element at the end of this deque.
Specified by:
`[offerLast](../../java/util/Deque.html#offerLast%28E%29)` in interface `[Deque](../../java/util/Deque.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Parameters:
`e` \- the element to add
Returns:
`true` (as specified by [Deque.offerLast(E)](../../java/util/Deque.html#offerLast%28E%29))
Throws:
`[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if the specified element is null
* #### removeFirst
public [E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque") removeFirst()
Description copied from interface: `[Deque](../../java/util/Deque.html#removeFirst%28%29)`
Retrieves and removes the first element of this deque. This method differs from [pollFirst](../../java/util/Deque.html#pollFirst%28%29) only in that it throws an exception if this deque is empty.
Specified by:
`[removeFirst](../../java/util/Deque.html#removeFirst%28%29)` in interface `[Deque](../../java/util/Deque.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Returns:
the head of this deque
Throws:
`[NoSuchElementException](../../java/util/NoSuchElementException.html "class in java.util")` \- if this deque is empty
* #### removeLast
public [E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque") removeLast()
Description copied from interface: `[Deque](../../java/util/Deque.html#removeLast%28%29)`
Retrieves and removes the last element of this deque. This method differs from [pollLast](../../java/util/Deque.html#pollLast%28%29) only in that it throws an exception if this deque is empty.
Specified by:
`[removeLast](../../java/util/Deque.html#removeLast%28%29)` in interface `[Deque](../../java/util/Deque.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Returns:
the tail of this deque
Throws:
`[NoSuchElementException](../../java/util/NoSuchElementException.html "class in java.util")` \- if this deque is empty
* #### getFirst
public [E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque") getFirst()
Description copied from interface: `[Deque](../../java/util/Deque.html#getFirst%28%29)`
Retrieves, but does not remove, the first element of this deque. This method differs from [peekFirst](../../java/util/Deque.html#peekFirst%28%29) only in that it throws an exception if this deque is empty.
Specified by:
`[getFirst](../../java/util/Deque.html#getFirst%28%29)` in interface `[Deque](../../java/util/Deque.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Returns:
the head of this deque
Throws:
`[NoSuchElementException](../../java/util/NoSuchElementException.html "class in java.util")` \- if this deque is empty
* #### getLast
public [E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque") getLast()
Description copied from interface: `[Deque](../../java/util/Deque.html#getLast%28%29)`
Retrieves, but does not remove, the last element of this deque. This method differs from [peekLast](../../java/util/Deque.html#peekLast%28%29) only in that it throws an exception if this deque is empty.
Specified by:
`[getLast](../../java/util/Deque.html#getLast%28%29)` in interface `[Deque](../../java/util/Deque.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Returns:
the tail of this deque
Throws:
`[NoSuchElementException](../../java/util/NoSuchElementException.html "class in java.util")` \- if this deque is empty
* #### removeFirstOccurrence
public boolean removeFirstOccurrence([Object](../../java/lang/Object.html "class in java.lang") o)
Removes the first occurrence of the specified element in this deque (when traversing the deque from head to tail). If the deque does not contain the element, it is unchanged. More formally, removes the first element `e` such that`o.equals(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).
Specified by:
`[removeFirstOccurrence](../../java/util/Deque.html#removeFirstOccurrence%28java.lang.Object%29)` in interface `[Deque](../../java/util/Deque.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Parameters:
`o` \- element to be removed from this deque, if present
Returns:
`true` if the deque contained the specified element
* #### removeLastOccurrence
public boolean removeLastOccurrence([Object](../../java/lang/Object.html "class in java.lang") o)
Removes the last occurrence of the specified element in this deque (when traversing the deque from head to tail). If the deque does not contain the element, it is unchanged. More formally, removes the last element `e` such that`o.equals(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).
Specified by:
`[removeLastOccurrence](../../java/util/Deque.html#removeLastOccurrence%28java.lang.Object%29)` in interface `[Deque](../../java/util/Deque.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Parameters:
`o` \- element to be removed from this deque, if present
Returns:
`true` if the deque contained the specified element
* #### add
public boolean add([E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque") e)
Inserts the specified element at the end of this deque.
This method is equivalent to [addLast(E)](../../java/util/ArrayDeque.html#addLast%28E%29).
Specified by:
`[add](../../java/util/Collection.html#add%28E%29)` in interface `[Collection](../../java/util/Collection.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Specified by:
`[add](../../java/util/Deque.html#add%28E%29)` in interface `[Deque](../../java/util/Deque.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Specified by:
`[add](../../java/util/Queue.html#add%28E%29)` in interface `[Queue](../../java/util/Queue.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Overrides:
`[add](../../java/util/AbstractCollection.html#add%28E%29)` in class `[AbstractCollection](../../java/util/AbstractCollection.html "class in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Parameters:
`e` \- the element to add
Returns:
`true` (as specified by [Collection.add(E)](../../java/util/Collection.html#add%28E%29))
Throws:
`[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if the specified element is null
* #### offer
public boolean offer([E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque") e)
Inserts the specified element at the end of this deque.
This method is equivalent to [offerLast(E)](../../java/util/ArrayDeque.html#offerLast%28E%29).
Specified by:
`[offer](../../java/util/Deque.html#offer%28E%29)` in interface `[Deque](../../java/util/Deque.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Specified by:
`[offer](../../java/util/Queue.html#offer%28E%29)` in interface `[Queue](../../java/util/Queue.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Parameters:
`e` \- the element to add
Returns:
`true` (as specified by [Queue.offer(E)](../../java/util/Queue.html#offer%28E%29))
Throws:
`[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if the specified element is null
* #### remove
public [E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque") remove()
Retrieves and removes the head of the queue represented by this deque. This method differs from [poll()](../../java/util/ArrayDeque.html#poll%28%29) only in that it throws an exception if this deque is empty.
This method is equivalent to [removeFirst()](../../java/util/ArrayDeque.html#removeFirst%28%29).
Specified by:
`[remove](../../java/util/Deque.html#remove%28%29)` in interface `[Deque](../../java/util/Deque.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Specified by:
`[remove](../../java/util/Queue.html#remove%28%29)` in interface `[Queue](../../java/util/Queue.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Returns:
the head of the queue represented by this deque
Throws:
`[NoSuchElementException](../../java/util/NoSuchElementException.html "class in java.util")` \- if this deque is empty
* #### poll
public [E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque") 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 [Deque.pollFirst()](../../java/util/Deque.html#pollFirst%28%29).
Specified by:
`[poll](../../java/util/Deque.html#poll%28%29)` in interface `[Deque](../../java/util/Deque.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Specified by:
`[poll](../../java/util/Queue.html#poll%28%29)` in interface `[Queue](../../java/util/Queue.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Returns:
the head of the queue represented by this deque, or`null` if this deque is empty
* #### element
public [E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque") element()
Retrieves, but does not remove, the head of the queue represented by this deque. This method differs from [peek](../../java/util/ArrayDeque.html#peek%28%29) only in that it throws an exception if this deque is empty.
This method is equivalent to [getFirst()](../../java/util/ArrayDeque.html#getFirst%28%29).
Specified by:
`[element](../../java/util/Deque.html#element%28%29)` in interface `[Deque](../../java/util/Deque.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Specified by:
`[element](../../java/util/Queue.html#element%28%29)` in interface `[Queue](../../java/util/Queue.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Returns:
the head of the queue represented by this deque
Throws:
`[NoSuchElementException](../../java/util/NoSuchElementException.html "class in java.util")` \- if this deque is empty
* #### peek
public [E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque") peek()
Retrieves, but does not remove, the head of the queue represented by this deque, or returns `null` if this deque is empty.
This method is equivalent to [Deque.peekFirst()](../../java/util/Deque.html#peekFirst%28%29).
Specified by:
`[peek](../../java/util/Deque.html#peek%28%29)` in interface `[Deque](../../java/util/Deque.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Specified by:
`[peek](../../java/util/Queue.html#peek%28%29)` in interface `[Queue](../../java/util/Queue.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Returns:
the head of the queue represented by this deque, or`null` if this deque is empty
* #### push
public void push([E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque") e)
Pushes an element onto the stack represented by this deque. In other words, inserts the element at the front of this deque.
This method is equivalent to [addFirst(E)](../../java/util/ArrayDeque.html#addFirst%28E%29).
Specified by:
`[push](../../java/util/Deque.html#push%28E%29)` in interface `[Deque](../../java/util/Deque.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Parameters:
`e` \- the element to push
Throws:
`[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if the specified element is null
* #### pop
public [E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque") 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 [removeFirst()](../../java/util/ArrayDeque.html#removeFirst%28%29).
Specified by:
`[pop](../../java/util/Deque.html#pop%28%29)` in interface `[Deque](../../java/util/Deque.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Returns:
the element at the front of this deque (which is the top of the stack represented by this deque)
Throws:
`[NoSuchElementException](../../java/util/NoSuchElementException.html "class in java.util")` \- if this deque is empty
* #### size
public int size()
Returns the number of elements in this deque.
Specified by:
`[size](../../java/util/Collection.html#size%28%29)` in interface `[Collection](../../java/util/Collection.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Specified by:
`[size](../../java/util/Deque.html#size%28%29)` in interface `[Deque](../../java/util/Deque.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Returns:
the number of elements in this deque
* #### isEmpty
public boolean isEmpty()
Returns `true` if this deque contains no elements.
Specified by:
`[isEmpty](../../java/util/Collection.html#isEmpty%28%29)` in interface `[Collection](../../java/util/Collection.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Overrides:
`[isEmpty](../../java/util/AbstractCollection.html#isEmpty%28%29)` in class `[AbstractCollection](../../java/util/AbstractCollection.html "class in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Returns:
`true` if this deque contains no elements
* #### iterator
public [Iterator](../../java/util/Iterator.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")> iterator()
Returns an iterator over the elements in this deque. The elements will be ordered from first (head) to last (tail). This is the same order that elements would be dequeued (via successive calls to[remove()](../../java/util/ArrayDeque.html#remove%28%29) or popped (via successive calls to [pop()](../../java/util/ArrayDeque.html#pop%28%29)).
Specified by:
`[iterator](../../java/util/Collection.html#iterator%28%29)` in interface `[Collection](../../java/util/Collection.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Specified by:
`[iterator](../../java/util/Deque.html#iterator%28%29)` in interface `[Deque](../../java/util/Deque.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Specified by:
`[iterator](../../java/lang/Iterable.html#iterator%28%29)` in interface `[Iterable](../../java/lang/Iterable.html "interface in java.lang")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Specified by:
`[iterator](../../java/util/AbstractCollection.html#iterator%28%29)` in class `[AbstractCollection](../../java/util/AbstractCollection.html "class in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Returns:
an iterator over the elements in this deque
* #### spliterator
public [Spliterator](../../java/util/Spliterator.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")> spliterator()
Specified by:
`[spliterator](../../java/util/Collection.html#spliterator%28%29)` in interface `[Collection](../../java/util/Collection.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Specified by:
`[spliterator](../../java/lang/Iterable.html#spliterator%28%29)` in interface `[Iterable](../../java/lang/Iterable.html "interface in java.lang")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Returns:
a `Spliterator` over the elements in this deque
Since:
1.8
* #### forEach
public void forEach([Consumer](../../java/util/function/Consumer.html "interface in java.util.function")<? super [E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")> action)
Description copied from interface: `[Iterable](../../java/lang/Iterable.html#forEach%28java.util.function.Consumer%29)`
Performs the given action for each element of the `Iterable` until all elements have been processed or the action throws an exception. Actions are performed in the order of iteration, if that order is specified. Exceptions thrown by the action are relayed to the caller.
The behavior of this method is unspecified if the action performs side-effects that modify the underlying source of elements, unless an overriding class has specified a concurrent modification policy.
Specified by:
`[forEach](../../java/lang/Iterable.html#forEach%28java.util.function.Consumer%29)` in interface `[Iterable](../../java/lang/Iterable.html "interface in java.lang")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Parameters:
`action` \- The action to be performed for each element
Throws:
`[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if the specified action is null
* #### removeIf
public boolean removeIf([Predicate](../../java/util/function/Predicate.html "interface in java.util.function")<? super [E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")> filter)
Description copied from interface: `[Collection](../../java/util/Collection.html#removeIf%28java.util.function.Predicate%29)`
Removes all of the elements of this collection that satisfy the given predicate. Errors or runtime exceptions thrown during iteration or by the predicate are relayed to the caller.
Specified by:
`[removeIf](../../java/util/Collection.html#removeIf%28java.util.function.Predicate%29)` in interface `[Collection](../../java/util/Collection.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Parameters:
`filter` \- a predicate which returns `true` for elements to be removed
Returns:
`true` if any elements were removed
Throws:
`[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if the specified filter is null
* #### removeAll
public boolean removeAll([Collection](../../java/util/Collection.html "interface in java.util")<?> c)
Removes all of this collection's elements that are also contained in the specified collection (optional operation). After this call returns, this collection will contain no elements in common with the specified collection.
Specified by:
`[removeAll](../../java/util/Collection.html#removeAll%28java.util.Collection%29)` in interface `[Collection](../../java/util/Collection.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Overrides:
`[removeAll](../../java/util/AbstractCollection.html#removeAll%28java.util.Collection%29)` in class `[AbstractCollection](../../java/util/AbstractCollection.html "class in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Parameters:
`c` \- collection containing elements to be removed from this collection
Returns:
`true` if this collection changed as a result of the call
Throws:
`[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if this collection contains one or more null elements and the specified collection does not support null elements ([optional](../../java/util/Collection.html#optional-restrictions)), or if the specified collection is null
See Also:
[AbstractCollection.remove(Object)](../../java/util/AbstractCollection.html#remove%28java.lang.Object%29), [AbstractCollection.contains(Object)](../../java/util/AbstractCollection.html#contains%28java.lang.Object%29)
* #### retainAll
public boolean retainAll([Collection](../../java/util/Collection.html "interface in java.util")<?> c)
Retains only the elements in this collection that are contained in the specified collection (optional operation). In other words, removes from this collection all of its elements that are not contained in the specified collection.
Specified by:
`[retainAll](../../java/util/Collection.html#retainAll%28java.util.Collection%29)` in interface `[Collection](../../java/util/Collection.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Overrides:
`[retainAll](../../java/util/AbstractCollection.html#retainAll%28java.util.Collection%29)` in class `[AbstractCollection](../../java/util/AbstractCollection.html "class in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Parameters:
`c` \- collection containing elements to be retained in this collection
Returns:
`true` if this collection changed as a result of the call
Throws:
`[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if this collection contains one or more null elements and the specified collection does not permit null elements ([optional](../../java/util/Collection.html#optional-restrictions)), or if the specified collection is null
See Also:
[AbstractCollection.remove(Object)](../../java/util/AbstractCollection.html#remove%28java.lang.Object%29), [AbstractCollection.contains(Object)](../../java/util/AbstractCollection.html#contains%28java.lang.Object%29)
* #### contains
public boolean contains([Object](../../java/lang/Object.html "class in java.lang") 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 `o.equals(e)`.
Specified by:
`[contains](../../java/util/Collection.html#contains%28java.lang.Object%29)` in interface `[Collection](../../java/util/Collection.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Specified by:
`[contains](../../java/util/Deque.html#contains%28java.lang.Object%29)` in interface `[Deque](../../java/util/Deque.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Overrides:
`[contains](../../java/util/AbstractCollection.html#contains%28java.lang.Object%29)` in class `[AbstractCollection](../../java/util/AbstractCollection.html "class in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Parameters:
`o` \- object to be checked for containment in this deque
Returns:
`true` if this deque contains the specified element
* #### remove
public boolean remove([Object](../../java/lang/Object.html "class in java.lang") o)
Removes a single instance 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`o.equals(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 [removeFirstOccurrence(Object)](../../java/util/ArrayDeque.html#removeFirstOccurrence%28java.lang.Object%29).
Specified by:
`[remove](../../java/util/Collection.html#remove%28java.lang.Object%29)` in interface `[Collection](../../java/util/Collection.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Specified by:
`[remove](../../java/util/Deque.html#remove%28java.lang.Object%29)` in interface `[Deque](../../java/util/Deque.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Overrides:
`[remove](../../java/util/AbstractCollection.html#remove%28java.lang.Object%29)` in class `[AbstractCollection](../../java/util/AbstractCollection.html "class in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Parameters:
`o` \- element to be removed from this deque, if present
Returns:
`true` if this deque contained the specified element
* #### clear
public void clear()
Removes all of the elements from this deque. The deque will be empty after this call returns.
Specified by:
`[clear](../../java/util/Collection.html#clear%28%29)` in interface `[Collection](../../java/util/Collection.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Overrides:
`[clear](../../java/util/AbstractCollection.html#clear%28%29)` in class `[AbstractCollection](../../java/util/AbstractCollection.html "class in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
* #### toArray
public [Object](../../java/lang/Object.html "class in java.lang")[] toArray()
Returns an array containing all of the elements in this deque in proper sequence (from first to last element).
The returned array will be "safe" in that no references to it are maintained by this deque. (In other words, this method must allocate a new array). The caller is thus free to modify the returned array.
This method acts as bridge between array-based and collection-based APIs.
Specified by:
`[toArray](../../java/util/Collection.html#toArray%28%29)` in interface `[Collection](../../java/util/Collection.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Overrides:
`[toArray](../../java/util/AbstractCollection.html#toArray%28%29)` in class `[AbstractCollection](../../java/util/AbstractCollection.html "class in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Returns:
an array containing all of the elements in this deque
* #### toArray
public <T> T[] toArray(T[] a)
Returns an array containing all of the elements in this deque in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array. If the deque fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this deque.
If this deque fits in the specified array with room to spare (i.e., the array has more elements than this deque), the element in the array immediately following the end of the deque is set to`null`.
Like the [toArray()](../../java/util/ArrayDeque.html#toArray%28%29) method, this method acts as bridge between array-based and collection-based APIs. Further, this method allows precise control over the runtime type of the output array, and may, under certain circumstances, be used to save allocation costs.
Suppose `x` is a deque known to contain only strings. The following code can be used to dump the deque into a newly allocated array of `String`:
`String[] y = x.toArray(new String[0]);`
Note that `toArray(new Object[0])` is identical in function to`toArray()`.
Specified by:
`[toArray](../../java/util/Collection.html#toArray%28T%5B%5D%29)` in interface `[Collection](../../java/util/Collection.html "interface in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Overrides:
`[toArray](../../java/util/AbstractCollection.html#toArray%28T%5B%5D%29)` in class `[AbstractCollection](../../java/util/AbstractCollection.html "class in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")>`
Type Parameters:
`T` \- the component type of the array to contain the collection
Parameters:
`a` \- the array into which the elements of the deque are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose
Returns:
an array containing all of the elements in this deque
Throws:
`[ArrayStoreException](../../java/lang/ArrayStoreException.html "class in java.lang")` \- if the runtime type of the specified array is not a supertype of the runtime type of every element in this deque
`[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if the specified array is null
* #### clone
public [ArrayDeque](../../java/util/ArrayDeque.html "class in java.util")<[E](../../java/util/ArrayDeque.html "type parameter in ArrayDeque")> clone()
Returns a copy of this deque.
Overrides:
`[clone](../../java/lang/Object.html#clone%28%29)` in class `[Object](../../java/lang/Object.html "class in java.lang")`
Returns:
a copy of this deque
See Also:
[Cloneable](../../java/lang/Cloneable.html "interface in java.lang")