Close

Java Collections - ArrayDeque.remove() Examples

[Last Updated: Dec 10, 2025]

Java Collections Java Java API 


Class:

java.util.ArrayDeque

java.lang.Objectjava.lang.Objectjava.util.AbstractCollectionjava.util.AbstractCollectionjava.util.CollectionCollectionjava.util.ArrayDequejava.util.ArrayDequejava.util.DequeDequejava.lang.CloneableCloneablejava.io.SerializableSerializableLogicBig

Methods:

public E remove()

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



public boolean remove(Object o)

Removes a single instance of the specified element from this deque. If the deque does not contain the element, it is unchanged.

This method is equivalent to removeFirstOccurrence().


Examples


package com.logicbig.example.arraydeque;

import java.util.ArrayDeque;
import java.util.List;

public class RemoveExample {

public static void main(String... args) {
ArrayDeque<Integer> ad = new ArrayDeque<>(List.of(3, 8, 1));
System.out.println(ad);
boolean b = ad.remove(8);
System.out.println(b);
System.out.println(ad);
}
}

Output

[3, 8, 1]
true
[3, 1]
JDK 25




package com.logicbig.example.arraydeque;

import java.util.ArrayDeque;
import java.util.List;

public class RemoveExample2 {

public static void main(String... args) {
ArrayDeque<Integer> ad = new ArrayDeque<>(List.of(3, 8, 1));
System.out.println(ad);
boolean b = ad.remove(null);
System.out.println(b);
System.out.println(ad);
}
}

Output

[3, 8, 1]
false
[3, 8, 1]
JDK 25




See Also