public class

ArrayDeque

extends AbstractCollection<E>
implements Deque<E>
java.lang.Object
   ↳ java.util.AbstractCollection<E>
     ↳ java.util.ArrayDeque<E>

Class Overview

An implementation of Deque, backed by an array. ArrayDeques have no size limit, can not contain null element, and they are not thread-safe. All optional operations are supported, and the elements can be any objects.

Summary

Public Constructors
ArrayDeque()
Constructs a new empty instance of ArrayDeque big enough for 16 elements.
ArrayDeque(int minSize)
Constructs a new empty instance of ArrayDeque big enough for specified number of elements.
ArrayDeque(Collection<? extends E> c)
Constructs a new instance of ArrayDeque containing the elements of the specified collection, with the order returned by the collection's iterator.
Public Methods
boolean add(Object e)
Inserts the element to the tail of the deque.
void addFirst(Object e)
void addLast(Object e)
void clear()
Empty the deque.
boolean contains(Object obj)
Returns true if the specified element is in the deque.
Iterator<E> descendingIterator()
Returns the iterator in reverse order, from tail to head.
E element()
Gets but does not remove the head element of this deque.
E getFirst()
Gets but not removes the head element of this deque.
E getLast()
Gets but not removes the tail element of this deque.
boolean isEmpty()
Returns true if the deque has no elements.
Iterator<E> iterator()
Returns the iterator of the deque.
boolean offer(Object e)
Inserts the element at the tail of the deque.
boolean offerFirst(Object e)
boolean offerLast(Object e)
E peek()
Gets but not removes the head element of this deque.
E peekFirst()
Gets but not removes the head element of this deque.
E peekLast()
Gets but not removes the tail element of this deque.
E poll()
Gets and removes the head element of this deque.
E pollFirst()
Gets and removes the head element of this deque.
E pollLast()
Gets and removes the tail element of this deque.
E pop()
Pops the head element of the deque, just same as removeFirst().
void push(Object e)
E remove()
Gets and removes the head element of this deque.
boolean remove(Object obj)
Removes the first equivalent element of the specified object.
E removeFirst()
Gets and removes the head element of this deque.
boolean removeFirstOccurrence(Object obj)
Removes the first equivalent element of the specified object.
E removeLast()
Gets and removes the tail element of this deque.
boolean removeLastOccurrence(Object obj)
Removes the last equivalent element of the specified object.
int size()
Returns the size of the deque.
[Expand]
Inherited Methods
From class java.util.AbstractCollection
From class java.lang.Object
From interface java.lang.Iterable
From interface java.util.Collection
From interface java.util.Deque
From interface java.util.Queue

Public Constructors

public ArrayDeque ()

Constructs a new empty instance of ArrayDeque big enough for 16 elements.

public ArrayDeque (int minSize)

Constructs a new empty instance of ArrayDeque big enough for specified number of elements.

Parameters
minSize the smallest size of the ArrayDeque

public ArrayDeque (Collection<? extends E> c)

Constructs a new instance of ArrayDeque containing the elements of the specified collection, with the order returned by the collection's iterator.

Parameters
c the source of the elements
Throws
NullPointerException if the collection is null

Public Methods

public boolean add (Object e)

Inserts the element to the tail of the deque.

Parameters
e the element
Returns
  • true

public void addFirst (Object e)

Parameters
e the element
Throws
NullPointerException if the element is null

public void addLast (Object e)

Parameters
e the element
Throws
NullPointerException if the element is null

public void clear ()

Empty the deque.

See Also

public boolean contains (Object obj)

Returns true if the specified element is in the deque.

Parameters
obj the element
Returns
  • true if the element is in the deque, false otherwise

public Iterator<E> descendingIterator ()

Returns the iterator in reverse order, from tail to head.

Returns
  • the reverse order Iterator

public E element ()

Gets but does not remove the head element of this deque. It throws an exception if the deque is empty.

Returns
  • the head element
Throws
NoSuchElementException if the deque is empty
See Also

public E getFirst ()

Gets but not removes the head element of this deque. This method throws an exception if the deque is empty.

Returns
  • the head element
Throws
NoSuchElementException if the deque is empty
See Also

public E getLast ()

Gets but not removes the tail element of this deque. This method throws an exception if the deque is empty.

Returns
  • the tail element
Throws
NoSuchElementException if the deque is empty
See Also

public boolean isEmpty ()

Returns true if the deque has no elements.

Returns
  • true if the deque has no elements, false otherwise
See Also

public Iterator<E> iterator ()

Returns the iterator of the deque. The elements will be ordered from head to tail.

Returns
  • the iterator
See Also

public boolean offer (Object e)

Inserts the element at the tail of the deque.

Parameters
e the element
Returns
  • true if the operation succeeds or false if it fails.
Throws
NullPointerException if the element is null

public boolean offerFirst (Object e)

Parameters
e the element
Returns
  • true
Throws
NullPointerException if the element is null

public boolean offerLast (Object e)

Parameters
e the element
Returns
  • true if the operation succeeds or false if it fails
Throws
NullPointerException if the element is null

public E peek ()

Gets but not removes the head element of this deque. This method returns null if the deque is empty.

Returns
  • the head element or null if the deque is empty
See Also

public E peekFirst ()

Gets but not removes the head element of this deque. This method returns null if the deque is empty.

Returns
  • the head element or null if the deque is empty
See Also

public E peekLast ()

Gets but not removes the tail element of this deque. This method returns null if the deque is empty.

Returns
  • the tail element or null if the deque is empty
See Also

public E poll ()

Gets and removes the head element of this deque. This method returns null if the deque is empty.

Returns
  • the head element or null if the deque is empty
See Also

public E pollFirst ()

Gets and removes the head element of this deque. This method returns null if the deque is empty.

Returns
  • the head element or null if the deque is empty
See Also

public E pollLast ()

Gets and removes the tail element of this deque. This method returns null if the deque is empty.

Returns
  • the tail element or null if the deque is empty
See Also

public E pop ()

Pops the head element of the deque, just same as removeFirst().

Returns
  • the head element
Throws
NoSuchElementException if the deque is empty
See Also

public void push (Object e)

Parameters
e the element to push
Throws
NullPointerException if the element is null

public E remove ()

Gets and removes the head element of this deque. This method throws an exception if the deque is empty.

Returns
  • the head element
Throws
NoSuchElementException if the deque is empty
See Also

public boolean remove (Object obj)

Removes the first equivalent element of the specified object. If the deque does not contain the element, it is unchanged and returns false.

Parameters
obj the element to be removed
Returns
  • true if the operation succeeds or false if the deque does not contain the element

public E removeFirst ()

Gets and removes the head element of this deque. This method throws an exception if the deque is empty.

Returns
  • the head element
Throws
NoSuchElementException if the deque is empty
See Also

public boolean removeFirstOccurrence (Object obj)

Removes the first equivalent element of the specified object. If the deque does not contain the element, it is unchanged and returns false.

Parameters
obj the element to be removed
Returns
  • true if the operation succeeds or false if the deque does not contain the element

public E removeLast ()

Gets and removes the tail element of this deque. This method throws an exception if the deque is empty.

Returns
  • the tail element
Throws
NoSuchElementException if the deque is empty
See Also

public boolean removeLastOccurrence (Object obj)

Removes the last equivalent element of the specified object. If the deque does not contain the element, it is unchanged and returns false.

Parameters
obj the element to be removed
Returns
  • true if the operation succeeds or false if the deque does not contain the element.

public int size ()

Returns the size of the deque.

Returns
  • the size of the deque
See Also