Java ArrayDeque Methods

Beginner
6 min read
Updated: Nov 2026
36 method guides
Method index

About This Index

This page is the Java ArrayDeque Methods index. Each row links to a full guide with syntax, parameters, return value, three runnable examples, and FAQs. Every example is a complete Java class with a main method and fixed data, so the output shown is the output you get.

Learn what an ArrayDeque is on the ArrayDeque hub. Use this page when you need a specific method such as push(), poll(), or peekFirst(). All examples compile on Java 8 and later.

Head and tail.

An ArrayDeque has two ends. The head (first, front) is where push, pop, poll, and peek work. The tail (last, back) is where add and offer put new elements. Printing a deque shows the elements from head to tail, like [a, b, c].

How to Call an ArrayDeque Method

Every method here is an instance method, so you call it on your deque variable:

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

Deque<String> deque = new ArrayDeque<>();
deque.addLast("b");                  // [b]
deque.addFirst("a");                 // [a, b]
deque.offer("c");                    // [a, b, c]  (tail)
String head = deque.peek();          // "a"        (looks only)
String gone = deque.poll();          // "a"        (removes the head)
int count = deque.size();            // 2

Java ArrayDeque Methods Table

All method guides in this Java tutorial series (36 tutorials), grouped by purpose.

Add elements

8 methods

Put new elements at the head (front) or the tail (back). The add* and push methods return nothing or true; the offer* methods return true. All of them throw NullPointerException for null.

MethodDescriptionTutorial
add()Append an element at the tail and get true back.Try it
addAll()Append every element of another collection at the tail.Try it
addFirst()Insert an element at the head (front) of the deque.Try it
addLast()Insert an element at the tail (end) of the deque.Try it
offer()Queue-style insert at the tail that returns true.Try it
offerFirst()Insert an element at the head and return true.Try it
offerLast()Insert an element at the tail and return true.Try it
push()Stack-style insert at the head of the deque.Try it

Remove from the ends

7 methods

Take an element off the head or the tail and get it back. The remove* and pop methods throw NoSuchElementException on an empty deque; the poll* methods return null instead.

MethodDescriptionTutorial
remove()Remove the head, or the first match of a value.Try it
removeFirst()Remove and return the head; throws if empty.Try it
removeLast()Remove and return the tail; throws if empty.Try it
poll()Remove and return the head, or null if empty.Try it
pollFirst()Remove and return the head, or null if empty.Try it
pollLast()Remove and return the tail, or null if empty.Try it
pop()Stack-style removal of the head; throws if empty.Try it

Look without removing

6 methods

Read the head or the tail and leave the deque unchanged. element and get* throw on an empty deque; peek* return null.

MethodDescriptionTutorial
element()Read the head without removing it; throws if empty.Try it
getFirst()Read the first element; throws if empty.Try it
getLast()Read the last element; throws if empty.Try it
peek()Read the head without removing it, or get null.Try it
peekFirst()Read the first element, or get null if empty.Try it
peekLast()Read the last element, or get null if empty.Try it

Search and remove by value

6 methods

Check whether a value is present, or remove elements by value, by another collection, or by a condition.

MethodDescriptionTutorial
contains()Check whether the deque holds a value (uses equals).Try it
removeFirstOccurrence()Remove the first element equal to a value.Try it
removeLastOccurrence()Remove the last element equal to a value.Try it
removeAll()Remove every element that is in another collection.Try it
retainAll()Keep only the elements that are in another collection.Try it
removeIf()Remove every element that matches a condition.Try it

Iterate, copy, and convert

6 methods

Walk the elements head to tail or tail to head, split them for streams, copy them into an array, or clone the whole deque.

MethodDescriptionTutorial
iterator()Walk the elements from head to tail.Try it
descendingIterator()Walk the elements from tail to head (reverse order).Try it
forEach()Run an action (lambda) for every element, head to tail.Try it
spliterator()Get a Spliterator for streams and parallel splitting.Try it
toArray()Copy the elements into an array, head to tail.Try it
clone()Make a shallow copy of the whole deque.Try it

Size and state

3 methods

Count the elements, check for an empty deque, or remove everything at once.

MethodDescriptionTutorial
size()Count how many elements the deque holds.Try it
isEmpty()Check whether the deque has no elements.Try it
clear()Remove every element at once.Try it

Frequently Asked Questions

They are the methods of java.util.ArrayDeque, a double-ended queue backed by a resizable array. They add, remove, and read elements at the head and the tail, search by value, iterate in both directions, and copy the elements out.
This index lists 36 guides, from add() and addFirst() to spliterator() and toArray(), grouped by what they do.
Both take an element off the deque. remove(), removeFirst(), removeLast(), and pop() throw NoSuchElementException when the deque is empty. poll(), pollFirst(), and pollLast() return null instead.
For a queue (first in, first out) use offer() to add at the tail, poll() to take from the head, and peek() to look. For a stack (last in, first out) use push(), pop(), and peek(), which all work at the head.
Read the Java ArrayDeque hub first. Then open add(), push(), poll(), and peek() from the tables below.

Start with add()

Put your first elements into an ArrayDeque and see where they go.

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

12 people found this page helpful