Java Deque offerFirst() Method

The offerFirst() method of Java Deque Interface is used to insert the given element in the front of the deque unless and until it violates the capacity restrictions. While using a capacity restricted deque , the above method is used for addFirst(E) method.

Syntax:

Parameter:

The above method requires only one parameter :

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

Return:

The above method is used to return a Boolean value, i.e., true if the element is added to the queue. Otherwise, returns false.

Throw:

ClassCastException- If the class for the given element avoids it from being added to the deque.

NullPointerException- If the specified element is a null and the given deque does not allow the null elements.

IlleagalArgumentException- If some properties of the specified element prevents it from being added to the deque.

Example 1

Test it Now

Output:

The final deque is given as : 
A
V
A
J

Example 2

Test it Now

Output:

The final deque is given as : 
language
secured
a
is
Java

Example 3

Test it Now

Output:

The final deque is given as : 
5
4
3
2
1
Next TopicJava Deque




Latest Courses