BlockingDeque remove() method in Java with Examples Last Updated : 14 Oct, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The remove() method of BlockingDeque removes the head of the Deque container. The method throws a NoSuchElementException if the Deque container is empty. If an element in passed in the parameter, it removes the given element if present in the Deque. Syntax: public E remove() or boolean remove(element) Parameters: This method accepts a temporary parameter element which is to be removed from the BlockingDeque Returns: This method returns true or false if the parameter is passed, else it returns nothing. It returns true if the element is there in the Deque, or else it returns false. Exception: The function throws a NoSuchElementException if the Deque is empty. Note: The remove() method of BlockingDeque has been inherited from the LinkedBlockingDeque class in Java. Below programs illustrate remove() method of BlockingDeque: Program 1: Java // Java Program Demonstrate remove() // method of BlockingDeque import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.BlockingDeque; import java.util.*; public class GFG { public static void main(String[] args) throws InterruptedException { // create object of BlockingDeque BlockingDeque<Integer> BD = new LinkedBlockingDeque<Integer>(); // Add numbers to end of BlockingDeque BD.add(7855642); BD.add(35658786); BD.add(5278367); BD.add(74381793); // print Deque System.out.println("Blocking Deque: " + BD); // removes the front element BD.remove(); System.out.println("Blocking Deque: " + BD); // removes the element BD.remove(5278367); System.out.println("Blocking Deque: " + BD); } } Output: Blocking Deque: [7855642, 35658786, 5278367, 74381793] Blocking Deque: [35658786, 5278367, 74381793] Blocking Deque: [35658786, 74381793] Program 2: Java // Java Program Demonstrate remove() // method of BlockingDeque import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.BlockingDeque; import java.util.*; public class GFG { public static void main(String[] args) throws InterruptedException { // create object of BlockingDeque BlockingDeque<Integer> BD = new LinkedBlockingDeque<Integer>(); // Add numbers to end of BlockingDeque BD.add(7855642); BD.add(35658786); BD.add(5278367); BD.add(74381793); // print Deque System.out.println("Blocking Deque: " + BD); BD.clear(); // removes the front element BD.remove(); System.out.println("Blocking Deque: " + BD); // removes the element BD.remove(5278367); System.out.println("Blocking Deque: " + BD); } } 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:29) Reference: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/BlockingDeque.html#remove() Comment More infoAdvertise with us Next Article BlockingDeque poll() method in Java with examples G gopaldave Follow Improve Article Tags : Java Java - util package Java-Functions Java-BlockingDeque Practice Tags : Java Similar Reads BlockingQueue remove() method in Java with examples The remove(Object obj) method of BlockingQueue removes only one instance of the given Object, passed as parameter, from this BlockingQueue if it is present. It removes an element e such that obj.equals(e) and if this queue contains one or more instance of element e. This method returns true if this 4 min read BlockingDeque take() method in Java with Examples The take() method of BlockingDeque returns and removes the head of the Deque container from it. The method throws an InterruptedException if it is interrupted while waiting. Syntax: public E take() Returns: This method returns the head of the Deque container. Exception: The function throws a Interru 2 min read BlockingDeque poll() method in Java with examples The poll() method of BlockingDeque returns the front element in the Deque container and deletes it. It returns null if the container is empty. Syntax: public E poll() Parameters: This method does not accept any parameters. Returns: This method returns front element of the Deque container if the cont 2 min read BlockingDeque removeLastOccurrence() method in Java with Examples The removeLastOccurrence() method of BlockingDeque 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 remov 2 min read BlockingQueue take() method in Java with examples The take() method of BlockingQueue interface is used to retrieve and remove the head of this queue. If the queue is empty then it will wait until an element becomes available. This method is more efficient if working on threads and using BlockingQueue in that process. So the thread that initially ca 4 min read BlockingDeque pollLast() method in Java with examples The pollLast() method of BlockingDeque returns the last element in the Deque container, and deletes it. It returns null if the container is empty. Syntax: public E pollLast() Parameters: This method does not accept any parameters. Returns: This method returns last element in the Deque container if t 2 min read Like