Home » Java Deque offer() Method with Examples

Java Deque offer() Method with Examples

by Online Tutorials Library

Java Deque offer() Method

The offer() method of Java Deque Interface inserts the given element into the queue which is represented by the particular deque.

Specified by:

offer in interface Queue<E>

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 :   Tina  Shyam  Isha  Falguni  

Example 2

Test it Now

Output:

The final deque is given as : [34, 43, 22, 55]  34  43  22  55  

Example 3

Test it Now

Output:

The final deque is given as :   H  E  L  L  O  
Next TopicJava Deque

You may also like