ConcurrentLinkedDeque addFirst() method in Java Last Updated : 17 Sep, 2018 Comments Improve Suggest changes Like Article Like Report The java.util.concurrent.ConcurrentLinkedDeque.addFirst() is an in-built function in Java which inserts the specified element at the front of the ConcurrentLinkedDeque. Syntax: conn_linked_deque.addFirst(elem) Parameter: The method accepts only a single parameter elem which is to be added to the beginning of the ConcurrentLinkedDeque. Return Value: The function has no return value. Exception:The method will throw NullPointerException when the parameter passed to the function is null. Due to its bounded nature, this method will never throw IllegalStateException or return false. Below programs illustrate the ConcurrentLinkedDeque.addFirst() method: Program 1: This program involves a ConcurrentLinkedDeque of Integer type. Java // Java Program Demonstrate addFirst() // 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(110); cld.addFirst(55); cld.addFirst(76); // Displaying the existing LinkedDeque System.out.println("Initial Elements in" + "the LinkedDeque: " + cld); // Insert a new element in the LinkedDeque cld.addFirst(21); // Displaying the modified LinkedDeque System.out.println("Initial Elements in" + "the LinkedDeque: " + cld); } } Output: Initial Elements inthe LinkedDeque: [76, 55, 110, 12] Initial Elements inthe LinkedDeque: [21, 76, 55, 110, 12] Program 2: This program involves a ConcurrentLinkedDeque of Integer type with Exception Handling when null is passed as parameter to the function. Java // Java Program Demonstrate addFirst() // method of ConcurrentLinkedDeque import java.util.concurrent.*; class ConcurrentLinkedDequeDemo { public static void main(String[] args) { ConcurrentLinkedDeque<String> cld = new ConcurrentLinkedDeque<String>(); cld.addFirst("Geeks"); cld.addFirst("Geek"); cld.addFirst("Gfg"); cld.addFirst("Contribute"); // Displaying the existing LinkedDeque System.out.println("Initial Elements in" + "the LinkedDeque: " + cld); /* Exception thrown when null is passed as parameter*/ try { cld.addFirst(null); } catch (NullPointerException e) { System.out.println("NullPointerException" + "thrown"); } // Insert a new element in the LinkedDeque cld.addFirst("Sudo Placement"); // Displaying the modified LinkedDeque System.out.println("Initial Elements in" + "the LinkedDeque: " + cld); } } Output: Initial Elements inthe LinkedDeque: [Contribute, Gfg, Geek, Geeks] NullPointerExceptionthrown Initial Elements inthe LinkedDeque: [Sudo Placement, Contribute, Gfg, Geek, Geeks] Reference: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentLinkedDeque.html#addFirst() Comment More infoAdvertise with us Next Article ConcurrentLinkedDeque addFirst() 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 addLast() method in Java The java.util.concurrent.ConcurrentLinkedDeque.addLast() is an in-built function in Java which inserts the specified element to the end of the deque. Syntax: conn_linked_deque.addLast(elem) Parameter: The method accepts only a single parameter elem which is to be added to the end of the ConcurrentLi 2 min read ConcurrentLinkedDeque add() method in Java The java.util.concurrent.ConcurrentLinkedDeque.add() is an in-built function in Java which inserts the specified element at the end of the deque. Syntax: conn_linked_deque.add(elem) Parameter: The method accepts only a single parameter elem which is to be added to tail of the ConcurentLinkedDeque. R 2 min read ConcurrentLinkedQueue add() method in Java The add() method of ConcurrentLinkedQueue is used to insert the element, passed as parameter to add() of ConcurrentLinkedQueue, at the tail of this ConcurrentLinkedQueue. This method returns True if insertion is successful. ConcurrentLinkedQueue is unbounded, so this method will never throw IllegalS 2 min read ConcurrentLinkedQueue addAll() method in Java The addAll() method of ConcurrentLinkedQueue is used to inserts all the elements of the Collection, passed as parameter to this method, at the end of a ConcurrentLinkedQueue. The insertion of element is in same order as returned by the collections iterator. Syntax: public boolean addAll(Collection 4 min read ConcurrentLinkedDeque getLast() Method in Java The java.util.concurrent.ConcurrentLinkedDeque.getLast() method is an in-built method in Java which returns the last element of the deque container. Syntax: Conn_Linked_Deque.getLast() Parameters: The method does not accept any parameter. Return Value: The method returns the last element present in 2 min read ConcurrentLinkedDeque element() method in Java The java.util.concurrent.ConcurrentLinkedDeque.element() is an in-built function in java which retrieves but does not remove the head of the queue represented by deque i.e the first element of deque.Syntax: conn_linked_deque.element() Parameter: This method has no parameters.Return Value: This metho 2 min read ConcurrentLinkedDeque getFirst() method in Java The java.util.concurrent.ConcurrentLinkedDeque.getFirst() method is an in-built method in Java which returns the first element of the deque container. Syntax: Conn_Linked_Deque.getFirst() Parameters: The method does not accept any parameter. Return Value: The method returns the first element present 2 min read ConcurrentLinkedDeque offerLast() Method in Java The java.util.concurrent.ConcurrentLinkedDeque.offerLast() method is an inbuilt method in Java which inserts the specified element, passed as a parameter, to the end of the deque. Syntax: Conn_Linked_Deque.offerLast(Object elem) Parameters: The method accepts a parameter elem which species the eleme 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 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