LinkedBlockingDeque removeLastOccurrence() method in Java
The removeLastOccurrence() method of LinkedBlockingDeque removes the last occurrence of the specified element from this deque. If the deque does not contain the element, it remains unchanged. It returns true if this deque contained the specified element, else it returns false.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
public boolean removeLastOccurrence(Object o)
Parameters: This method accepts a mandatory parameter o which specifies the element whose last occurrence is to be removed from the Dequeue container.
Returns: This method returns true if the element is present and removed from the Deque container, else it returns false.
Below programs illustrate removeLastOccurrence() method of LinkedBlockingDeque:
Program 1: When element is present.
Linked Blocking Deque: [15, 20, 20, 15] Last occurrence of 15 removed Linked Blocking Deque: [15, 20, 20]
Program 2: When element is not present.
Linked Blocking Deque: [15, 20, 20, 15] 10 not present and not removed Linked Blocking Deque: [15, 20, 20, 15]