LinkedBlockingDeque removeFirst() method in Java Last Updated : 26 Nov, 2018 Comments Improve Suggest changes Like Article Like Report The removeFirst() method of LinkedBlockingDeque returns and removes the first element of the Deque container from it. The method throws an NoSuchElementException if the Deque container is empty. Syntax: public E removeFirst() Returns: This method returns the head of the Deque container, which is the first element. Exception: The function throws a NoSuchElementException if the Deque is empty. Below programs illustrate removeFirst() method of LinkedBlockingDeque: Program 1: Java // Java Program to demonstrate removeFirst() // 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 Dequee System.out.println("Linked Blocking Deque: " + LBD); // removes the front element and prints it System.out.println("First element of Linked Blocking Deque: " + LBD.removeFirst()); // prints the Deque System.out.println("Linked Blocking Deque: " + LBD); } } Output: Linked Blocking Deque: [7855642, 35658786, 5278367, 74381793] First element of Linked Blocking Deque: 7855642 Linked Blocking Deque: [35658786, 5278367, 74381793] Program 2: Java // Java Program to demonstrate removeFirst() // 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>(); // print Dequee System.out.println("Linked Blocking Deque: " + LBD); try { // throws an exception LBD.removeFirst(); } catch (Exception e) { System.out.println("Exception when removing " + "first element from this Deque: " + e); } } } Output: Linked Blocking Deque: [] Exception when removing first element from this Deque: java.util.NoSuchElementException Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/LinkedBlockingDeque.html#removeFirst-- Comment More infoAdvertise with us Next Article LinkedBlockingDeque removeFirst() method in Java G gopaldave Follow Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions Java-LinkedBlockingDeque +2 More Practice Tags : JavaJava-CollectionsMisc Similar Reads LinkedBlockingDeque offerFirst() method in Java The offerFirst(E e) method of LinkedBlockingDeque inserts the element passed in the parameter at the front of the Deque container. If the container's capacity has exceeded, then it does not returns an exception as in case of add() and addFirst() function. Syntax: public boolean offerFirst(E e) Param 2 min read LinkedBlockingDeque push() method in Java The push(E e) method of LinkedBlockingDeque pushes an element onto the stack represented by this deque. It inserts the element passed in the parameter to the front of the Deque if there is space. If the LinkedBlockingDeque is capacity restricted and no space is left for insertion, it returns an Ille 2 min read LinkedBlockingDeque peek() method in Java The peek() method of LinkedBlockingDeque returns the front element in the Deque container. It returns null if the container is empty. Syntax: public E peek() Parameters: This method does not accept any parameters. Returns: This method returns front element in the Deque container if the container is 2 min read LinkedBlockingDeque poll() method in Java The poll() method of LinkedBlockingDeque 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 th 2 min read LinkedBlockingDeque contains() method in Java The contains(Object o) method of LinkedBlockingDeque checks if the passed element in the parameter exists in the container or not. It returns true if the element exists in the container else it returns a false value. Syntax: public boolean contains(Object o) Parameters: This method accepts a mandato 2 min read LinkedBlockingDeque offerLast() method in Java The offerLast(E e) method of LinkedBlockingDeque inserts the element passed in the parameter at the end of the Deque container. If the container's capacity has exceeded, then it does not returns an exception as in case of add() and addLast() function. Syntax: public boolean offerLast(E e) Parameters 2 min read LinkedBlockingDeque pollLast() method in Java The pollLast() method of LinkedBlockingDeque 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 containe 2 min read LinkedBlockingDeque pollFirst() method in Java The pollFirst() method of LinkedBlockingDeque returns the front element in the Deque container, and deletes it. It returns null if the container is empty. Syntax: public E pollFirst() Parameters: This method does not accept any parameters. Returns: This method returns front element in the Deque cont 2 min read LinkedBlockingDeque addLast() method in Java The addLast(E e) method of LinkedBlockingDeque inserts the element passed in the parameter to the end of the Deque if there is space. If the LinkedBlockingDeque is capacity restricted and no space is left for insertion, it returns an IllegalStateException. Syntax: public void addLast(E e) Parameters 2 min read LinkedBlockingDeque removeLast() method in Java 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 retur 2 min read Like