ConcurrentLinkedDeque push() method in Java with Examples Last Updated : 26 Dec, 2018 Comments Improve Suggest changes Like Article Like Report The push() method of ConcurrentLinkedDeque class is an in-built function in Java which pushes an element onto the stack represented by this deque (in other words, at the head of this deque) if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available. Syntax: public void push(E e) Here, E is the type of element maintained by this collection class. Parameter: This method accepts only a single parameter element which is to be added at the head of the ConcurentLinkedDeque. Return Value:The function has no return value. Exception:The method will throw the following exceptions. IllegalStateException: if the element cannot be added at this time due to capacity restrictions. ClassCastException: if the class of the specified element prevents it from being added to this deque. NullPointerException: if the specified element is null and this deque does not permit null elements. IllegalArgumentException: if some property of the specified element prevents it from being added to this deque. Below programs illustrate the ConcurrentLinkedDeque.push() method: Program 1: This program involves a ConcurrentLinkedDeque of Character type. Java // Java program to demonstrate push() // method of ConcurrentLinkedDeque import java.util.concurrent.*; public class GFG { public static void main(String[] args) { // Creating an empty ConcurrentLinkedDeque ConcurrentLinkedDeque<String> CLD = new ConcurrentLinkedDeque<String>(); // Use push() method to add elements CLD.push("Welcome"); CLD.push("To"); CLD.push("Geeks"); CLD.push("For"); CLD.push("Geeks"); // Displaying the ConcurrentLinkedDeque System.out.println("ConcurrentLinkedDeque: " + CLD); } } Output: ConcurrentLinkedDeque: [Geeks, For, Geeks, To, Welcome] Program 2: To show NullPointerException. Java // Java program to demonstrate push() // method of ConcurrentLinkedDeque import java.util.concurrent.*; public class GFG { public static void main(String[] args) { // Creating an empty ConcurrentLinkedDeque ConcurrentLinkedDeque<String> CLD = new ConcurrentLinkedDeque<String>(); // Displaying the ConcurrentLinkedDeque System.out.println("ConcurrentLinkedDeque: " + CLD); try { System.out.println("Trying to add " + "null in ConcurrentLinkedDeque"); // Use push() method to null element CLD.push(null); } catch (Exception e) { System.out.println(e); } } } Output: ConcurrentLinkedDeque: [] Trying to add null in ConcurrentLinkedDeque java.lang.NullPointerException Comment More infoAdvertise with us Next Article ConcurrentLinkedDeque push() method in Java with Examples S suman_ptnl Follow Improve Article Tags : Java Java-Collections Java - util package Java-Functions Java-ConcurrentLinkedDeque +1 More Practice Tags : JavaJava-Collections Similar Reads ConcurrentLinkedDeque pop() method in Java with Examples The Java.util.ConcurrentLinkedDeque.pop() method in Java is used to pop an element from the ConcurrentLinkedDeque. The element is popped from the top of the ConcurrentLinkedDeque and is removed from the same.Syntax: ConcurrentLinkedDeque.pop() Parameters: The method does not take any parameters.Retu 2 min read ConcurrentLinkedDeque poll() method in Java with Example The poll() method of ConcurrentLinkedDeque 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 2 min read ConcurrentLinkedDeque peek() method in Java with Example The java.util.ConcurrentLinkedDeque.peek() method in Java is used to retrieve or fetch the element at the head of the Deque. The element retrieved does not get deleted or removed from the Deque instead the method just returns it. If no element is present in the deque then Null is returned. Syntax: A 2 min read ConcurrentLinkedDeque offer() method in Java with Examples The java.util.concurrent.ConcurrentLinkedDeque.offer() method is an inbuilt method in Java which inserts the specified element, passed as a parameter, to the deque. Syntax: public boolean offer(E elem) Parameters: The method accepts a parameter elem which species the element to be inserted to the de 2 min read ConcurrentLinkedDeque remove() method in Java with Examples The java.util.concurrent.ConcurrentLinkedDeque.remove() is an in-built function in Java which is used to remove an element from this deque.Syntax: public E remove() or public boolean remove(Object o) Parameters: The first overload of this method does not accepts any parameter. However the second ove 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 ConcurrentLinkedDeque toArray() method in Java with Example toArray() The Java.util.concurrent.ConcurrentLinkedDeque.toArray() method returns an array containing all the elements in the deque in proper sequence i.e. from first to last. The returned array will be safe as a new array is created (hence new memory is allocated). Thus the caller is free to modify 3 min read ConcurrentLinkedDeque iterator() method in Java with Example The Java.util.concurrent.ConcurrentLinkedDeque.iterator() method is used to return an iterator of the same elements as that of the ConcurrentLinkedDeque. The elements are returned in random order from what was present in the deque. Syntax: Iterator iterate_value = ConcurrentLinkedDeque.iterator(); P 2 min read BlockingDeque push() method in Java with examples The push(E e) method of BlockingDeque 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 BlockingDeque is capacity restricted and no space is left for insertion, it returns an IllegalStateExce 2 min read BlockingDeque put() method in Java with Examples The put(E e) method of BlockingDeque inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque). If the Deque is capacity restricted, then it will wait for the space to become available. Syntax: public void put(E e) Parameters: This method acce 2 min read Like