VOOZH about

URL: https://www.geeksforgeeks.org/java/concurrentlinkeddeque-removelastoccurrence-method-in-java/

⇱ ConcurrentLinkedDeque removeLastOccurrence() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

ConcurrentLinkedDeque removeLastOccurrence() Method in Java

Last Updated : 15 Nov, 2022

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 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 removeLastOccurrence() method : 

Output:
Elements in the LinkedDeque: [Geeks, gfg, Gfg, Geeks, GFG]
Elements in the LinkedDeque: [Geeks, gfg, Gfg, GFG]

Program 2: 

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#removeLastOccurrence()

Comment