Java Deque push() Method

The push() method of Deque interface is used to push an element on the stack represented by the given deque. The above method is equivalent to addFirst() method.

Syntax:

Parameter:

The above requires only one parameter:

  1. The element 'e' that needs to be pushed.

Throw:

  • IlleagalStateException- If the element is not able to be added due to capacity restriction.
  • NullPointerException- If the specified element is already null and the given deque does not allow the null elements.
  • IlleagalArgumentException- If some properties of the specified element prevent it from being added to the deque.

Example 1

Test it Now

Output:

The final deque is given as : 
a
b
c
d

Example 2

Test it Now

Output:

The final deque is : [Hello,  , World]

Example 3

Test it Now

Output:

The resultant deque is represented as : 
85
75
65
55
Next TopicJava Deque




Latest Courses