In Java, addAll(c) appends every element of the collection c to the tail of an ArrayDeque. The elements are added in the order the collection's iterator returns them, as if you called addLast once for each of them.
It returns true if the deque changed, which happens whenever c has at least one element, and false for an empty collection. The source collection itself is not modified.
An instance method of java.util.ArrayDeque (Java 1.6+): a resizable-array deque with no capacity limit, no null elements, and no thread safety.
Syntax
Pass any Collection whose element type fits the deque, such as a List, a Set, or another deque.
Java
Deque<String> deque = new ArrayDeque<>();
deque.add("start");
boolean changed = deque.addAll(Arrays.asList("a", "b")); // true
// deque = [start, a, b]
Call
What it does
deque.addAll(list)
Appends the list's elements in list order.
deque.addAll(otherDeque)
Appends the other deque's elements from its head to its tail.
deque.addAll(emptyList)
Adds nothing and returns false.
new ArrayDeque<>(list)
Constructor shortcut: a new deque that starts with the list's elements.
The parameter type is Collection<? extends E>, so a List<Integer> can be added to a Deque<Number>. Older JDKs inherit addAll from AbstractCollection; newer ones override it in ArrayDeque to grow the array once. The result is the same.
Library declarations
Java
// java.util.ArrayDeque<E>
public boolean addAll(Collection<? extends E> c)
// Declared in Collection<E> and Deque<E>
Parameters
Parameter
Description
c
Required. The collection whose elements are appended. Must not be null, and must not contain null elements.
Return Value
Return Value
Description
boolean
true if at least one element was added; false if c was empty.