The java.util.concurrent.ConcurrentLinkedDeque.removeFirstOccurrence() method is an in-built method in Java which accepts a parameter and removes the first appearance of that element in the deque. Thus, in case the element is not present in the deque, it remains unchanged. Syntax:
public boolean removeFirstOccurrence(Object o)
Parameters: The function accepts an object elem as parameter which denotes the object whose first appearance from the deque is to be removed. Return Value: The function returns true if elem is present in the deque and returns false otherwise. Exception: The function throws NullPointerException if the specified element passed as parameter to the function is null. Below programs illustrate the use of removeFirstOccurrence() method : Program 1:Â
Java
/* Java program to demonstrate   removeFirstOccurrence() method   of ConcurrentLinkedDeque  */Â
import java.util.concurrent.*;Â
class ConcurrentLinkedDequeDemo {Â Â Â Â public static void main(String[] args)Â Â Â Â {Â Â Â Â Â Â Â Â ConcurrentLinkedDeque<String> cld = new ConcurrentLinkedDeque<String>();Â
        cld.addFirst("GFG");        cld.addFirst("Geeks");        cld.addFirst("Gfg");        cld.addFirst("gfg");        cld.addFirst("Geeks");Â
        // Displaying the existing LinkedDeque        System.out.println("Elements in "                           + "the LinkedDeque: " + cld);Â
        // Remove first occurrence of element        cld.removeFirstOccurrence("Geeks");Â
        // Displaying the modified LinkedDeque        System.out.println("Elements in "                           + "the LinkedDeque: " + cld);    }} |
Elements in the LinkedDeque: [Geeks, gfg, Gfg, Geeks, GFG] Elements in the LinkedDeque: [gfg, Gfg, Geeks, GFG]
Program 2:Â
Java
/* Java program to demonstrate   removeFirstOccurrence() method   of ConcurrentLinkedDeque  */Â
import java.util.concurrent.*;Â
class ConcurrentLinkedDequeDemo {Â Â Â Â public static void main(String[] args)Â Â Â Â {Â Â Â Â Â Â Â Â ConcurrentLinkedDeque<Integer> cld = new ConcurrentLinkedDeque<Integer>();Â
        cld.addFirst(12);        cld.addFirst(280);        cld.addFirst(1008);        cld.addFirst(1050);        cld.addFirst(379);Â
        // Displaying the existing LinkedDeque        System.out.println("Elements in "                           + "the LinkedDeque: " + cld);        try {            // Remove first occurrence of element            cld.removeFirstOccurrence(null);        }        catch (Exception e) {            System.out.println(e);        }    }} |
Elements in the LinkedDeque: [379, 1050, 1008, 280, 12] java.lang.NullPointerException
