The removeLast() method of LinkedBlockingDeque returns and removes the element at tail of the Deque container. The method throws an NoSuchElementException if the Deque container is empty.
Syntax:
public E removeLast()
Parameters: This method does not accepts any parameter.
Returns: This method returns the tail of the Deque container.
Exception: The function throws a NoSuchElementException if the Deque is empty.
Below programs illustrate removeLast() method of LinkedBlockingDeque:
Program 1:
// Java Program to demonstrate removeLast() // 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(7855642); LBD.add(35658786); LBD.add(5278367); LBD.add(74381793); // print Dequeue System.out.println("Linked Blocking Deque: " + LBD); // removes the last element and prints it System.out.println("Linked Blocking Deque: " + LBD.removeLast()); // prints the Deque System.out.println("Linked Blocking Deque: " + LBD); } } |
Linked Blocking Deque: [7855642, 35658786, 5278367, 74381793] Linked Blocking Deque: 74381793 Linked Blocking Deque: [7855642, 35658786, 5278367]
Program 2:
// Java Program to demonstrate removeLast() // method of LinkedBlockingDeque import java.util.concurrent.LinkedBlockingDeque; import java.util.*; public class GFG { public static void main(String[] args) throws NoSuchElementException { // create object of LinkedBlockingDeque LinkedBlockingDeque<Integer> LBD = new LinkedBlockingDeque<Integer>(); // Add numbers to end of LinkedBlockingDeque LBD.add(7855642); LBD.add(35658786); LBD.add(5278367); LBD.add(74381793); // print Dequeue System.out.println("Linked Blocking Deque: " + LBD); // Deque is empty LBD.clear(); // throws an exception LBD.removeLast(); } } |
Output:
Exception in thread "main" java.util.NoSuchElementException
at java.util.concurrent.LinkedBlockingDeque.removeLast(LinkedBlockingDeque.java:462)
at GFG.main(GFG.java:29)
Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/LinkedBlockingDeque.html#removeLast–
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- ConcurrentLinkedDeque removeLast() method in Java
- LinkedList removeLast() Method in Java
- ArrayDeque removeLast() Method in Java
- LinkedBlockingDeque take() method in Java
- LinkedBlockingDeque contains() method in Java
- LinkedBlockingDeque put() method in Java
- LinkedBlockingDeque pop() method in Java
- LinkedBlockingDeque add() method in Java
- LinkedBlockingDeque peekFirst() method in Java
- LinkedBlockingDeque descendingIterator() method in Java
- LinkedBlockingDeque isEmpty() method in Java with Example
- LinkedBlockingDeque poll() method in Java
- LinkedBlockingDeque pollFirst() method in Java
- LinkedBlockingDeque pollLast() method in Java
- LinkedBlockingDeque remainingCapacity() method in Java
- LinkedBlockingDeque size() method in Java
- LinkedBlockingDeque equals() method in Java with Example
- LinkedBlockingDeque removeLastOccurrence() method in Java
- LinkedBlockingDeque removeFirstOccurrence() 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.

