The remove() method of LinkedBlockingDeque removes the head of the Deque container. The method throws a NoSuchElementException if the Deque container is empty.
Syntax:
public E remove()
Parameters: This method does not accepts any parameter.
Returns: This method does not returns anything.
Exception: The function throws a NoSuchElementException if the Deque is empty.
Below programs illustrate remove() method of LinkedBlockingDeque:
Program 1:
// Java Program Demonstrate remove() // 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 front element LBD.remove(); System.out.println("Linked Blocking Deque: " + LBD); } } |
Linked Blocking Deque: [7855642, 35658786, 5278367, 74381793] Linked Blocking Deque: [35658786, 5278367, 74381793]
Program 2:
// Java Program Demonstrate remove() // 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>(6); // 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.remove(); } } |
Output:
Exception in thread "main" java.util.NoSuchElementException
at java.util.concurrent.LinkedBlockingDeque.removeFirst(LinkedBlockingDeque.java:453)
at java.util.concurrent.LinkedBlockingDeque.remove(LinkedBlockingDeque.java:672)
at GFG.main(GFG.java:30)
Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/LinkedBlockingDeque.html#remove–
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- LinkedBlockingDeque putFirst() method in Java
- LinkedBlockingDeque getFirst() method in Java
- LinkedBlockingDeque iterator() method in Java
- LinkedBlockingDeque contains() method in Java
- LinkedBlockingDeque getLast() method in Java
- LinkedBlockingDeque removeLastOccurrence() method in Java
- LinkedBlockingDeque size() method in Java
- LinkedBlockingDeque clear() method in Java
- LinkedBlockingDeque element() method in Java
- LinkedBlockingDeque addLast() method in Java
- LinkedBlockingDeque add() method in Java
- LinkedBlockingDeque addFirst() method in Java
- LinkedBlockingDeque push() method in Java
- LinkedBlockingDeque pop() method in Java
- LinkedBlockingDeque offer() method in Java
- LinkedBlockingDeque offerFirst() method in Java
- LinkedBlockingDeque offerLast() method in Java
- LinkedBlockingDeque peek() method in Java
- LinkedBlockingDeque peekLast() method in Java
- LinkedBlockingDeque poll() 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.

