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.
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.
ConcurrentLinkedDeque: [Geeks, For, Geeks, To, Welcome]
Program 2: To show NullPointerException.
ConcurrentLinkedDeque:  Trying to add null in ConcurrentLinkedDeque java.lang.NullPointerException
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.