ConcurrentLinkedDeque add() method in Java Last Updated : 17 Sep, 2018 Comments Improve Suggest changes Like Article Like Report 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. 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.add() method: Program 1: This program involves a ConcurrentLinkedDeque of Integer type. Java // Java Program Demonstrate add() // method of ConcurrentLinkedDeque import java.util.concurrent.*; class ConcurrentLinkedDequeDemo { public static void main(String[] args) { ConcurrentLinkedDeque<Integer> cld = new ConcurrentLinkedDeque<Integer>(); cld.add(12); cld.add(110); cld.add(55); cld.add(76); // Displaying the existing LinkedDeque System.out.println("Initial Elements in" + "the LinkedDeque: " + cld); // Insert a new element in the LinkedDeque cld.add(21); // Displaying the modified LinkedDeque System.out.println("Initial Elements in" + "the LinkedDeque: " + cld); } } Output: Initial Elements inthe LinkedDeque: [12, 110, 55, 76] Initial Elements inthe LinkedDeque: [12, 110, 55, 76, 21] Program 2: This program involves a ConcurrentLinkedDeque of String type with Exception Handling when null is passed as parameter to the function. Java // Java Program Demonstrate add() // method of ConcurrentLinkedDeque import java.util.concurrent.*; class ConcurrentLinkedDequeDemo { public static void main(String[] args) { ConcurrentLinkedDeque<String> cld = new ConcurrentLinkedDeque<String>(); cld.add("Gfg"); cld.add("GFG"); cld.add("Geeksforgeeks"); cld.add("Contribute"); // Displaying the existing LinkedDeque System.out.println("Initial Elements in" + "the LinkedDeque: " + cld); /* Exception thrown when null is passed as parameter*/ try { cld.add(null); } catch (NullPointerException e) { System.out.println("NullPointerException" + "thrown"); } // Insert a new element in the LinkedDeque cld.add("Geek Classes"); // Displaying the modified LinkedDeque System.out.println("Initial Elements in" + "the LinkedDeque: " + cld); } } Output: Initial Elements inthe LinkedDeque: [Gfg, GFG, Geeksforgeeks, Contribute] NullPointerExceptionthrown Initial Elements inthe LinkedDeque: [Gfg, GFG, Geeksforgeeks, Contribute, Geek Classes] Reference: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentLinkedDeque.html#add() Comment More infoAdvertise with us Next Article ConcurrentLinkedDeque add() 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 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 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 addFirst() method in Java 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 beg 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 in Java The ConcurrentLinkedDeque class in Java is a part of the Java Collection Framework and implements the Collection interface and the AbstractCollection class. It belongs to java.util.concurrent package. It is used to implement Deque with the help of LinkedList concurrently.Iterators and spliterators a 10 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 ConcurrentLinkedQueue size() method in Java The size() method of ConcurrentLinkedQueue is used to returns number of elements that this ConcurrentLinkedQueue contains. Syntax: public int size() Returns: This method number of elements in this ConcurrentLinkedQueue. Below programs illustrate size() method of ConcurrentLinkedQueue: Example 1: Jav 2 min read ConcurrentLinkedQueue offer() method in Java The offer() method of ConcurrentLinkedQueue is used to insert the element, passed as parameter, at the tail of this ConcurrentLinkedQueue. This method returns True if insertion is successful. ConcurrentLinkedQueue is unbounded, so this method offer() will never returns false. Syntax: public boolean 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 addAll() method in Java with Examples The addAll(Collection col) of ConcurrentLinkedDeque which takes col as a parameter, where col is a Collection of elements (List, ArrayList, LinkedList etc). This entire Collection gets appended or added to the end of the Dequeue. This method just like add() method returns true if the Collection gets 3 min read Like