Packages

class ArrayDeque[E] extends AbstractCollection[E] with Deque[E] with Cloneable with Serializable

Resizable-array implementation of the Deque interface. Array deques have no capacity restrictions; they grow as necessary to support usage. They are not thread-safe; in the absence of external synchronization, they do not support concurrent access by multiple threads. Null elements are prohibited. This class is likely to be faster than java.util.Stack when used as a stack, and faster than LinkedList when used as a queue.

Exceptions include remove, removeFirstOccurrence, removeLastOccurrence, contains, iterator.remove(), and the bulk operations, all of which run in linear time.

The iterators returned by this class's iterator method are fail-fast: If the deque is modified at any time after the iterator is created, in any way except through the iterator's own remove method, the iterator will generally throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.

Note that the fail-fast behavior of an iterator cannot be guaranteed as it is, generally speaking, impossible to make any hard guarantees in the presence of unsynchronized concurrent modification. Fail-fast iterators throw ConcurrentModificationException on a best-effort basis. Therefore, it would be wrong to write a program that depended on this exception for its correctness: the fail-fast behavior of iterators should be used only to detect bugs.

This class and its iterator implement all of the optional methods of the Collection and Iterator interfaces.

This class is a member of the <a href="/java.base/java/util/package-summary.html#CollectionsFramework"> Java Collections Framework.

Since

1.6

Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ArrayDeque
  2. Serializable
  3. Cloneable
  4. Deque
  5. SequencedCollection
  6. Queue
  7. AbstractCollection
  8. Collection
  9. Iterable
  10. AnyRef
  11. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new ArrayDeque(c: Collection[_ <: E])

    Constructs a deque containing the elements of the specified collection, in the order they are returned by the collection's iterator.

    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.)

    c

    the collection whose elements are to be placed into the deque

    Exceptions thrown

    java.lang.NullPointerException if the specified collection is null

  2. new ArrayDeque(numElements: Int)

    Constructs an empty array deque with an initial capacity sufficient to hold the specified number of elements.

    Constructs an empty array deque with an initial capacity sufficient to hold the specified number of elements.

    numElements

    lower bound on initial capacity of the deque

  3. new ArrayDeque()

    Constructs an empty array deque with an initial capacity sufficient to hold 16 elements.

  4. new ArrayDeque(elements: Array[AnyRef])

Type Members

  1. final class DeqSpliterator extends Spliterator[E]

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def add(e: E): Boolean

    Inserts the specified element at the end of this deque.

    Inserts the specified element at the end of this deque.

    This method is equivalent to #addLast.

    e

    the element to add

    returns

    true (as specified by Collection#add)

    Definition Classes
    ArrayDequeDequeQueueAbstractCollectionCollection
    Exceptions thrown

    java.lang.NullPointerException if the specified element is null

  5. def addAll(c: Collection[_ <: E]): Boolean

    Adds all of the elements in the specified collection at the end of this deque, as if by calling #addLast on each one, in the order that they are returned by the collection's iterator.

    Adds all of the elements in the specified collection at the end of this deque, as if by calling #addLast on each one, in the order that they are returned by the collection's iterator.

    c

    the elements to be inserted into this deque

    returns

    true if this deque changed as a result of the call

    Definition Classes
    ArrayDequeAbstractCollectionCollection
    Exceptions thrown

    java.lang.NullPointerException if the specified collection or any of its elements are null

  6. def addFirst(e: E): Unit

    Inserts the specified element at the front of this deque.

    Inserts the specified element at the front of this deque.

    e

    the element to add

    Definition Classes
    ArrayDequeDeque
    Exceptions thrown

    java.lang.NullPointerException if the specified element is null

  7. def addLast(e: E): Unit

    Inserts the specified element at the end of this deque.

    Inserts the specified element at the end of this deque.

    This method is equivalent to #add.

    e

    the element to add

    Definition Classes
    ArrayDequeDeque
    Exceptions thrown

    java.lang.NullPointerException if the specified element is null

  8. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  9. def bulkRemove(filter: Predicate[_ >: E]): Boolean

    Implementation of bulk remove methods.

  10. def clear(): Unit

    Removes all of the elements from this deque.

    Removes all of the elements from this deque. The deque will be empty after this call returns.

    Definition Classes
    ArrayDequeAbstractCollectionCollection
  11. def clone(): ArrayDeque[E]

    Returns a copy of this deque.

    Returns a copy of this deque.

    returns

    a copy of this deque

    Definition Classes
    ArrayDeque → AnyRef
  12. def contains(o: Any): Boolean

    Returns true if this deque contains the specified element.

    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).

    o

    object to be checked for containment in this deque

    returns

    true if this deque contains the specified element

    Definition Classes
    ArrayDequeDequeAbstractCollectionCollection
  13. def containsAll(c: Collection[_]): Boolean
    Definition Classes
    AbstractCollectionCollection
  14. def descendingIterator(): Iterator[E]
    Definition Classes
    ArrayDequeDeque
  15. def element(): E

    Retrieves, but does not remove, the head of the queue represented by this deque.

    Retrieves, but does not remove, the head of the queue represented by this deque. This method differs from peek only in that it throws an exception if this deque is empty.

    This method is equivalent to #getFirst.

    returns

    the head of the queue represented by this deque

    Definition Classes
    ArrayDequeDequeQueue
    Exceptions thrown
  16. var elements: Array[AnyRef]
  17. def ensureCapacity(minCapacity: Int): Unit

    Increases the internal storage of this collection, if necessary, to ensure that it can hold at least the given number of elements.

    Increases the internal storage of this collection, if necessary, to ensure that it can hold at least the given number of elements.

    minCapacity

    the desired minimum capacity

    Since

    TBD

  18. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  19. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  20. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  21. def forEach(action: Consumer[_ >: E]): Unit

    Definition Classes
    ArrayDequeIterable
    Exceptions thrown
  22. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  23. def getFirst(): E

    Definition Classes
    ArrayDequeDeque
    Exceptions thrown
  24. def getLast(): E

    Definition Classes
    ArrayDequeDeque
    Exceptions thrown
  25. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  26. var head: Int

    The index of the element at the head of the deque (which is the element that would be removed by remove() or pop()); or an arbitrary number 0 <= head < elements.length equal to tail if the deque is empty.

  27. def isEmpty(): Boolean

    Returns true if this deque contains no elements.

    Returns true if this deque contains no elements.

    returns

    true if this deque contains no elements

    Definition Classes
    ArrayDequeAbstractCollectionCollection
  28. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  29. def iterator(): Iterator[E]

    Returns an iterator over the elements in this deque.

    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 or popped (via successive calls to #pop).

    returns

    an iterator over the elements in this deque

    Definition Classes
    ArrayDequeDequeAbstractCollectionCollectionIterable
  30. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  31. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  32. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  33. def offer(e: E): Boolean

    Inserts the specified element at the end of this deque.

    Inserts the specified element at the end of this deque.

    This method is equivalent to #offerLast.

    e

    the element to add

    returns

    true (as specified by Queue#offer)

    Definition Classes
    ArrayDequeDequeQueue
    Exceptions thrown

    java.lang.NullPointerException if the specified element is null

  34. def offerFirst(e: E): Boolean

    Inserts the specified element at the front of this deque.

    Inserts the specified element at the front of this deque.

    e

    the element to add

    returns

    true (as specified by Deque#offerFirst)

    Definition Classes
    ArrayDequeDeque
    Exceptions thrown

    java.lang.NullPointerException if the specified element is null

  35. def offerLast(e: E): Boolean

    Inserts the specified element at the end of this deque.

    Inserts the specified element at the end of this deque.

    e

    the element to add

    returns

    true (as specified by Deque#offerLast)

    Definition Classes
    ArrayDequeDeque
    Exceptions thrown

    java.lang.NullPointerException if the specified element is null

  36. def parallelStream(): Stream[E]
    Definition Classes
    Collection
  37. def peek(): E

    Retrieves, but does not remove, the head of the queue represented by this deque, or returns null if this deque is empty.

    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 #peekFirst.

    returns

    the head of the queue represented by this deque, or null if this deque is empty

    Definition Classes
    ArrayDequeDequeQueue
  38. def peekFirst(): E
    Definition Classes
    ArrayDequeDeque
  39. def peekLast(): E
    Definition Classes
    ArrayDequeDeque
  40. def poll(): E

    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.

    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 #pollFirst.

    returns

    the head of the queue represented by this deque, or null if this deque is empty

    Definition Classes
    ArrayDequeDequeQueue
  41. def pollFirst(): E
    Definition Classes
    ArrayDequeDeque
  42. def pollLast(): E
    Definition Classes
    ArrayDequeDeque
  43. def pop(): E

    Pops an element from the stack represented by this deque.

    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.

    returns

    the element at the front of this deque (which is the top of the stack represented by this deque)

    Definition Classes
    ArrayDequeDeque
    Exceptions thrown
  44. def push(e: E): Unit

    Pushes an element onto the stack represented by this deque.

    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

    the element to push

    Definition Classes
    ArrayDequeDeque
    Exceptions thrown

    java.lang.NullPointerException if the specified element is null

  45. def remove(o: Any): Boolean

    Removes a single instance of the specified element from this deque.

    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.

    o

    element to be removed from this deque, if present

    returns

    true if this deque contained the specified element

    Definition Classes
    ArrayDequeDequeAbstractCollectionCollection
  46. def remove(): E

    Retrieves and removes the head of the queue represented by this deque.

    Retrieves and removes the head of the queue represented by this deque.

    This method differs from poll() only in that it throws an exception if this deque is empty.

    This method is equivalent to #removeFirst.

    returns

    the head of the queue represented by this deque

    Definition Classes
    ArrayDequeDequeQueue
    Exceptions thrown
  47. def removeAll(c: Collection[_]): Boolean

    Definition Classes
    ArrayDequeAbstractCollectionCollection
    Exceptions thrown
  48. def removeFirst(): E

    Definition Classes
    ArrayDequeDeque
    Exceptions thrown
  49. def removeFirstOccurrence(o: Any): Boolean

    Removes the first occurrence of the specified element in this deque (when traversing the deque from head to tail).

    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).

    o

    element to be removed from this deque, if present

    returns

    true if the deque contained the specified element

    Definition Classes
    ArrayDequeDeque
  50. def removeIf(filter: Predicate[_ >: E]): Boolean

    Definition Classes
    ArrayDequeCollection
    Exceptions thrown
  51. def removeLast(): E

    Definition Classes
    ArrayDequeDeque
    Exceptions thrown
  52. def removeLastOccurrence(o: Any): Boolean

    Removes the last occurrence of the specified element in this deque (when traversing the deque from head to tail).

    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 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).

    o

    element to be removed from this deque, if present

    returns

    true if the deque contained the specified element

    Definition Classes
    ArrayDequeDeque
  53. def replaceAll(operator: UnaryOperator[E]): Unit

    Replaces each element of this deque with the result of applying the operator to that element, as specified by List#replaceAll.

    Replaces each element of this deque with the result of applying the operator to that element, as specified by List#replaceAll.

    operator

    the operator to apply to each element

    Since

    TBD

  54. def retainAll(c: Collection[_]): Boolean

    Definition Classes
    ArrayDequeAbstractCollectionCollection
    Exceptions thrown
  55. def size(): Int

    Returns the number of elements in this deque.

    Returns the number of elements in this deque.

    returns

    the number of elements in this deque

    Definition Classes
    ArrayDequeDequeAbstractCollectionCollection
  56. def spliterator(): Spliterator[E]

    Creates a late-binding and fail-fast Spliterator over the elements in this deque.

    Creates a late-binding and fail-fast Spliterator over the elements in this deque.

    The Spliterator reports Spliterator.SIZED, Spliterator.SUBSIZED, Spliterator.ORDERED, and Spliterator.NONNULL. Overriding implementations should document the reporting of additional characteristic values.

    returns

    a Spliterator over the elements in this deque

    Definition Classes
    ArrayDequeCollectionIterable
    Since

    1.8

  57. def stream(): Stream[E]
    Definition Classes
    Collection
  58. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  59. var tail: Int

    The index at which the next element would be added to the tail of the deque (via addLast(E), add(E), or push(E)); elements[tail] is always null.

  60. def toArray[T <: AnyRef](a: Array[T]): Array[T]

    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.

    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()* 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().

    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

    Definition Classes
    ArrayDequeAbstractCollectionCollection
    Exceptions thrown

    java.lang.ArrayStoreException if the runtime type of the specified array is not a supertype of the runtime type of every element in this deque

    java.lang.NullPointerException if the specified array is null

  61. def toArray(): Array[AnyRef]

    Returns an array containing all of the elements in this deque in proper sequence (from first to last element).

    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.

    returns

    an array containing all of the elements in this deque

    Definition Classes
    ArrayDequeAbstractCollectionCollection
  62. def toString(): String
    Definition Classes
    AbstractCollection → AnyRef → Any
  63. def trimToSize(): Unit

    Minimizes the internal storage of this collection.

    Minimizes the internal storage of this collection.

    Since

    TBD

  64. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  65. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  66. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from Serializable

Inherited from Cloneable

Inherited from Deque[E]

Inherited from SequencedCollection[E]

Inherited from Queue[E]

Inherited from AbstractCollection[E]

Inherited from Collection[E]

Inherited from Iterable[E]

Inherited from AnyRef

Inherited from Any

Ungrouped