![]() |
VOOZH | about |
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 IllegalStateException. This function is similar to that of addFirst().
Syntax:
public void push(E e)
Parameters: This method accepts a mandatory parameter e which is the element to be inserted at the front of the LinkedBlockingDeque.
Note: The push() method of BlockingDeque has been inherited from the LinkedBlockingDeque class in Java.
Returns: This method does not return anything.
Exception:
Below programs illustrate push() method of BlockingDeque:
Program 1:
Blocking Deque: [74381793, 5278367, 35658786, 7855642]
Program 2:
Output:
Exception in thread "main" java.lang.IllegalStateException: Deque full at java.util.concurrent.LinkedBlockingDeque.addFirst(LinkedBlockingDeque.java:326) at java.util.concurrent.LinkedBlockingDeque.push(LinkedBlockingDeque.java:770) at GFG.main(GFG.java:24)
Program 3:
Output:
Exception in thread "main" java.lang.NullPointerException at java.util.concurrent.LinkedBlockingDeque.offerFirst(LinkedBlockingDeque.java:342) at java.util.concurrent.LinkedBlockingDeque.addFirst(LinkedBlockingDeque.java:325) at java.util.concurrent.LinkedBlockingDeque.push(LinkedBlockingDeque.java:770) at GFG.main(GFG.java:24)
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/BlockingDeque.html#push(E)