Tuesday, October 7, 2025
HomeLanguagesJavaConcurrentLinkedDeque remove() method in Java with Examples

ConcurrentLinkedDeque remove() method in Java with Examples

The java.util.concurrent.ConcurrentLinkedDeque.remove() is an in-built function in Java which is used to remove an element from this deque.
Syntax: 
 

public E remove()
        or
public boolean remove(Object o)

Parameters: The first overload of this method does not accepts any parameter. However the second overload of this method accepts an element o as parameter which is to be removed from this ConcurrentLinkedDeque.
Return Value: This method returns the element removed if no particular element is specified as parameter. if an element is specified as parameter, then it returns a boolean value stating whether this element is removed or not.
Exception: The first overload of this function throws a NoSuchElementException if this deque is empty. Whereas the second overload throws NullPointerException if the specified element is null.
Below programs illustrate the ConcurrentLinkedDeque.remove() method:
Example: 1
 

Java




// Java Program to demonstrate
// ConcurrentLinkedDeque remove() method
 
import java.util.concurrent.*;
 
class ConcurrentLinkedDequeDemo {
    public static void main(String[] args)
    {
 
        // Create a ConcurrentLinkedDeque
        // using ConcurrentLinkedDeque() constructor
        ConcurrentLinkedDeque<Integer>
            cld = new ConcurrentLinkedDeque<Integer>();
 
        cld.add(40);
        cld.add(50);
        cld.add(60);
        cld.add(70);
        cld.add(80);
 
        // Displaying the existing LinkedDeque
        System.out.println("Existing ConcurrentLinkedDeque: "
                           + cld);
 
        // remove method removes the first element of queue
        // using remove() method
        System.out.println("Element removed: "
                           + cld.remove());
 
        // Displaying the existing LinkedDeque
        System.out.println("Modified ConcurrentLinkedDeque: "
                           + cld);
    }
}


Output: 

Existing ConcurrentLinkedDeque: [40, 50, 60, 70, 80]
Element removed: 40
Modified ConcurrentLinkedDeque: [50, 60, 70, 80]

 

Example: 2
 

Java




// Java Program to demonstrate
// ConcurrentLinkedDeque remove(Object o) method
 
import java.util.concurrent.*;
 
class ConcurrentLinkedDequeDemo {
    public static void main(String[] args)
    {
        ConcurrentLinkedDeque<String> cld
            = new ConcurrentLinkedDeque<String>();
 
        cld.add("GFG");
        cld.add("Gfg");
        cld.add("Lazyroar");
        cld.add("Geeks");
 
        // Displaying the existing LinkedDeque
        System.out.println("Elements in"
                           + "the LinkedDeque: " + cld);
 
        // Remove "Gfg" using remove(Object)
        System.out.println("Gfg removed: "
                           + cld.remove("Gfg"));
 
        // Displaying the elements
        System.out.println("Elements in"
                           + "the LinkedDeque: " + cld);
    }
}


Output: 

Elements inthe LinkedDeque: [GFG, Gfg, Lazyroar, Geeks]
Gfg removed: true
Elements inthe LinkedDeque: [GFG, Lazyroar, Geeks]

 

RELATED ARTICLES

Most Popular

Dominic
32340 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6709 POSTS0 COMMENTS
Nicole Veronica
11874 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11937 POSTS0 COMMENTS
Shaida Kate Naidoo
6832 POSTS0 COMMENTS
Ted Musemwa
7091 POSTS0 COMMENTS
Thapelo Manthata
6781 POSTS0 COMMENTS
Umr Jansen
6785 POSTS0 COMMENTS