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 removeLastOccurrence(Object o)
Parameters: The function accepts an object elem as parameter which denotes the object whose last appearance from the deque is to be removed.
Return Value: The function returns true if elem is present in th edeque 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 removeLastOccurrence() method :
/* Java program to demonstrate removeLastOccurence() 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 last occurence of element cld.removeLastOccurrence("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: [Geeks, gfg, Gfg, GFG]
Program 2:
/* Java program to demonstrate removeLastOccurence() 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 last occurence of element cld.removeLastOccurrence(null); } catch (Exception e) { System.out.println(e); } } } |
Elements in the LinkedDeque: [379, 1050, 1008, 280, 12] java.lang.NullPointerException
Recommended Posts:
- LinkedBlockingDeque removeLastOccurrence() method in Java
- LinkedList removeLastOccurrence() method in Java with Example
- ArrayDeque removeLastOccurrence() Method in Java
- BlockingDeque removeLastOccurrence() method in Java with Examples
- ConcurrentLinkedDeque add() method in Java
- ConcurrentLinkedDeque hashCode() method in Java with Example
- ConcurrentLinkedDeque addLast() method in Java
- ConcurrentLinkedDeque size() method in Java
- ConcurrentLinkedDeque addFirst() method in Java
- ConcurrentLinkedDeque peekFirst() method in Java
- ConcurrentLinkedDeque removeLast() method in Java
- ConcurrentLinkedDeque clear() method in Java
- ConcurrentLinkedDeque removeFirst() method in Java
- ConcurrentLinkedDeque contains() method in Java with Examples
- ConcurrentLinkedDeque toArray() method in Java with Example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



