Java ArrayDeque addAll() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
ArrayDeque

Definition

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]
CallWhat 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

ParameterDescription
cRequired. The collection whose elements are appended. Must not be null, and must not contain null elements.

Return Value

Return ValueDescription
booleantrue if at least one element was added; false if c was empty.

Compare with Similar Methods

Ways to put several elements into a deque:

MethodHow it differs
add(e)One element at a time; addAll is the bulk version.
addFirst(e) in a loopPuts each element at the head, so the result ends up in reverse order. addAll keeps the original order.
new ArrayDeque<>(c)Creates a new deque from a collection instead of adding to an existing one.
retainAll(c)The opposite direction: keeps only elements that are in c.

Java Examples

Example 1 — Append a List to a Deque

Start with one element, then add a whole list in one call.

Java
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.List;

public class ArrayDequeAddAllDemo {
    public static void main(String[] args) {
        Deque<String> deque = new ArrayDeque<>();
        deque.add("start");

        List<String> more = Arrays.asList("a", "b", "c");
        boolean changed = deque.addAll(more);

        System.out.println("Changed: " + changed);
        System.out.println("Deque: " + deque);
        System.out.println("List: " + more);
    }
}

How It Works

  1. An existing element. The deque already holds "start" before the bulk call.
  2. Bulk append. addAll(more) adds a, b, and c after start, in list order.
  3. true means changed. Three elements were added, so changed is true.
  4. The source is untouched. The list still prints [a, b, c]; the elements were copied into the deque, not moved.

Example 2 — Adding an Empty Collection Returns false

See when addAll reports false, and that duplicates from the source are kept.

Java
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;

public class ArrayDequeAddAllEmpty {
    public static void main(String[] args) {
        Deque<Integer> nums = new ArrayDeque<>(Arrays.asList(1, 2));

        boolean changed = nums.addAll(new ArrayList<Integer>());
        System.out.println("Changed: " + changed);
        System.out.println(nums);

        nums.addAll(Arrays.asList(3, 3));
        System.out.println(nums);
    }
}

How It Works

  1. Constructor copy. new ArrayDeque<>(Arrays.asList(1, 2)) creates a deque that already holds 1 and 2.
  2. Nothing to add. The new ArrayList is empty, so the deque does not change and addAll returns false.
  3. Both copies arrive. Arrays.asList(3, 3) has two equal values, and both are appended, giving [1, 2, 3, 3].
  4. Using the result. Checking the returned boolean is a quick way to know whether the source had any elements at all.

Example 3 — Append One Deque to Another

The second deque is filled with push(), so its head-to-tail order is the reverse of the push order. addAll follows that head-to-tail order.

Java
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;

public class ArrayDequeAddAllMerge {
    public static void main(String[] args) {
        Deque<String> first = new ArrayDeque<>(Arrays.asList("x", "y"));
        Deque<String> second = new ArrayDeque<>();
        second.push("p");
        second.push("q");

        System.out.println("second: " + second);
        first.addAll(second);
        System.out.println("first:  " + first);
        System.out.println("sizes:  " + first.size() + " and " + second.size());
    }
}

How It Works

  1. Build the source. Pushing p and then q puts q at the head, so second prints [q, p].
  2. Iterator order decides. addAll walks second from head to tail, so q is appended before p.
  3. Appended after the old tail. first keeps x and y at the front and becomes [x, y, q, p].
  4. Copy, not move. second still has its 2 elements, while first now has 4.

Frequently Asked Questions

It appends every element of the given collection at the tail of the deque, in the collection iteration order.
true if the deque changed (the collection had at least one element), false if the collection was empty.
No, always at the tail. To put many elements at the head, call addFirst() in a loop, which reverses their order.
addAll() throws NullPointerException, because ArrayDeque does not allow null elements. Elements before the null may already have been added.
Yes. Any Collection works. The elements are copied from its head to its tail, and the source deque is not changed.

Next: addFirst()

Insert an element at the head (front) of the deque.

addFirst() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful