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.
Syntax:
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.
// Java Program to demonstrate removeLastOccurrence() // method of LinkedBlockingDeque import java.util.concurrent.LinkedBlockingDeque; import java.util.*; public class GFG { public static void main(String[] args) throws InterruptedException { // create object of LinkedBlockingDeque LinkedBlockingDeque<Integer> LBD = new LinkedBlockingDeque<Integer>(); // Add numbers to end of LinkedBlockingDeque LBD.add(15); LBD.add(20); LBD.add(20); LBD.add(15); // print Dequeue System.out.println("Linked Blocking Deque: " + LBD); if (LBD.removeLastOccurrence(15)) System.out.println("Last occurrence of 15 removed"); else System.out.println("15 not present and not removed"); // prints the Deque after removal System.out.println("Linked Blocking Deque: " + LBD); } } |
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.
// Java Program to demonstrate removeLastOccurrence() // method of LinkedBlockingDeque import java.util.concurrent.LinkedBlockingDeque; import java.util.*; public class GFG { public static void main(String[] args) throws InterruptedException { // create object of LinkedBlockingDeque LinkedBlockingDeque<Integer> LBD = new LinkedBlockingDeque<Integer>(); // Add numbers to end of LinkedBlockingDeque LBD.add(15); LBD.add(20); LBD.add(20); LBD.add(15); // print Dequeue System.out.println("Linked Blocking Deque: " + LBD); if (LBD.removeLastOccurrence(10)) System.out.println("Last occurrence of 10 removed"); else System.out.println("10 not present and not removed"); // prints the Deque after removal System.out.println("Linked Blocking Deque: " + LBD); } } |
Linked Blocking Deque: [15, 20, 20, 15] 10 not present and not removed Linked Blocking Deque: [15, 20, 20, 15]
Recommended Posts:
- ArrayDeque removeLastOccurrence() Method in Java
- ConcurrentLinkedDeque removeLastOccurrence() Method in Java
- LinkedList removeLastOccurrence() method in Java with Example
- LinkedBlockingDeque take() method in Java
- LinkedBlockingDeque add() method in Java
- LinkedBlockingDeque pop() method in Java
- LinkedBlockingDeque put() method in Java
- LinkedBlockingDeque contains() method in Java
- LinkedBlockingDeque pollLast() method in Java
- LinkedBlockingDeque putLast() method in Java
- LinkedBlockingDeque poll() method in Java
- LinkedBlockingDeque spliterator() method in Java
- LinkedBlockingDeque pollFirst() method in Java
- LinkedBlockingDeque remainingCapacity() method in Java
- LinkedBlockingDeque remove() method in Java
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.



