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.
The above method requires only one parameter :
The above method is used to return a Boolean value, i.e., true if the element is added to the queue. Otherwise, returns false.
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 1Test it Now
The final deque is given as : A V A J
Example 2Test it Now
The final deque is given as : language secured a is Java
Example 3Test it Now
The final deque is given as : 5 4 3 2 1