ConcurrentLinkedDeque removeFirstOccurrence() method in Java Last Updated : 15 Nov, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report 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); } } Output: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); } } } Output:Elements in the LinkedDeque: [379, 1050, 1008, 280, 12] java.lang.NullPointerException Reference:https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentLinkedDeque.html#removeFirstOccurrence() Comment More infoAdvertise with us Next Article ArrayDeque removeFirstOccurrence() Method in Java R RICHIK BHATTACHARJEE Follow Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions Java-ConcurrentLinkedDeque +2 More Practice Tags : JavaJava-CollectionsMisc Similar Reads ConcurrentLinkedDeque removeLastOccurrence() Method in Java The java.util.concurrent.ConcurrentLinkedDeque.removeLastOccurrence() method is an in-built method in Java which accepts a parameter and removes the last appearance of that element in the deque. Thus, in case the element is not present in the deque, it remains unchanged. Syntax: public boolean remov 2 min read ConcurrentLinkedDeque removeFirst() method in Java The ConcurrentLinkedDeque.removeFirst() is an in-built function in Java which removes the first element from the deque container. The function throws a NoSuchElementException if this deque is empty. Syntax: Conn_Linked_Deque.removeFirst() Parameters: The function does not accepts any parameter. Retu 2 min read ConcurrentLinkedDeque removeLast() method in Java The ConcurrentLinkedDeque.removeLast() is an in-built function in Java which removes the last element in the deque. The function throws a NoSuchElementException if this deque is empty. Syntax: Conn_Linked_Deque.removeLast() Parameters: The function does not accepts any parameter. Return Values: The 2 min read ConcurrentLinkedDeque peekFirst() method in Java The java.util.concurrent.ConcurrentLinkedDeque.peekFirst() is an in-built method in Java which retrieves the first element of this deque without removing it. The function returns NULL if the deque is empty. Syntax: Conn_Linked_Deque.peekFirst() Parameters: This function does not accepts any paramete 2 min read ArrayDeque removeFirstOccurrence() Method in Java The java.util.ArrayDeque.removeFirstOccurrence(Object) method in Java is used to remove the first occurrence of a specific element from this deque. If the element is present only once, then that element is removed and true is returned. If no such element is removed then false is returned. Syntax: Ar 2 min read ConcurrentLinkedDeque offerFirst() method in Java The java.util.concurrent.ConcurrentLinkedDeque.offerFirst() method is an inbuilt method in Java which inserts the specified element, passed as a parameter, in the front of the deque. Syntax: Conn_Linked_Deque.offerFirst(Object elem) Parameters: The method accepts a parameter elem which species the e 2 min read Like