ConcurrentLinkedDeque removeFirst() method in Java Last Updated : 18 Sep, 2018 Comments Improve Suggest changes Like Article Like Report The ConcurrentLinkedDeque.removeFirst() is an in-built function in Java which removes the first element from the deque container. The function throws a NoSuchElementException if this deque is empty. Syntax: Conn_Linked_Deque.removeFirst() Parameters: The function does not accepts any parameter. Return Values: The function returns the first element in the deque. Exception: The function throws a NoSuchElementException if this deque is empty. Below program illustrates the removeFirst() method: Program 1: This program involves deque with Integer elements. Java // Java Program to demonstrate removeFirst() // method of ConcurrentLinkedDeque import java.util.concurrent.*; class ConcurrentLinkedDequeDemo { public static void main(String[] args) { ConcurrentLinkedDeque<Integer> cld = new ConcurrentLinkedDeque<Integer>(); cld.addFirst(12); cld.addFirst(70); cld.addFirst(1009); cld.addFirst(475); // Displaying the existing LinkedDeque System.out.println("Elements in" + "the LinkedDeque: " + cld); // Display the first element System.out.println("Element removed : " + cld.peekFirst()); // Remove the first element cld.removeFirst(); // Displaying the elements System.out.println("Elements in" + "the LinkedDeque: " + cld); } } Output: Elements inthe LinkedDeque: [475, 1009, 70, 12] Element removed : 475 Elements inthe LinkedDeque: [1009, 70, 12] Program 2: This program involves deque with String elements. Java // Java Program Demonstrate removeFirst() // method of ConcurrentLinkedDeque import java.util.concurrent.*; class ConcurrentLinkedDequeDemo { public static void main(String[] args) { ConcurrentLinkedDeque<String> cld = new ConcurrentLinkedDeque<String>(); cld.addFirst("GFG"); cld.addFirst("Gfg"); cld.addFirst("GeeksforGeeks"); cld.addFirst("Geeks"); // Displaying the existing LinkedDeque System.out.println("Elements in" + "the LinkedDeque: " + cld); // Display the first element System.out.println("Element removed : " + cld.peekFirst()); // Remove the first element cld.removeFirst(); // Displaying the elements System.out.println("Elements in" + "the LinkedDeque: " + cld); } } Output: Elements inthe LinkedDeque: [Geeks, GeeksforGeeks, Gfg, GFG] Element removed : Geeks Elements inthe LinkedDeque: [GeeksforGeeks, Gfg, GFG] Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentLinkedDeque.html#removeFirst() Comment More infoAdvertise with us Next Article ConcurrentLinkedDeque removeFirst() method in Java R RICHIK BHATTACHARJEE Follow Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions Java-ConcurrentLinkedDeque +2 More Practice Tags : JavaJava-CollectionsMisc Similar Reads ConcurrentLinkedDeque removeLast() method in Java The ConcurrentLinkedDeque.removeLast() is an in-built function in Java which removes the last element in the deque. The function throws a NoSuchElementException if this deque is empty. Syntax: Conn_Linked_Deque.removeLast() Parameters: The function does not accepts any parameter. Return Values: The 2 min read ConcurrentLinkedDeque peekFirst() method in Java The java.util.concurrent.ConcurrentLinkedDeque.peekFirst() is an in-built method in Java which retrieves the first element of this deque without removing it. The function returns NULL if the deque is empty. Syntax: Conn_Linked_Deque.peekFirst() Parameters: This function does not accepts any paramete 2 min read ConcurrentLinkedDeque offerFirst() method in Java The java.util.concurrent.ConcurrentLinkedDeque.offerFirst() method is an inbuilt method in Java which inserts the specified element, passed as a parameter, in the front of the deque. Syntax: Conn_Linked_Deque.offerFirst(Object elem) Parameters: The method accepts a parameter elem which species the e 2 min read ConcurrentLinkedDeque removeFirstOccurrence() method in Java The java.util.concurrent.ConcurrentLinkedDeque.removeFirstOccurrence() method is an in-built method in Java which accepts a parameter and removes the first appearance of that element in the deque. Thus, in case the element is not present in the deque, it remains unchanged. Syntax: public boolean rem 2 min read ConcurrentLinkedDeque pollFirst() method in Java The java.util.concurrent.ConcurrentLinkedDeque.pollFirst() is an in-built method in Java which retrieves the first element of this deque and removes it. If the deque is empty, the method returns NULL. Syntax: Conn_Linked_Deque.pollFirst() Parameters: This function does not accepts any parameter. Ret 2 min read Like