Java Deque offerLast() Method

The offerLast() method of Java Deque Interface is used to insert the given element at the end of the deque unless and until it violates the capacity restriction. While using a capacity-restricted deque, this method is preferred over addLast(E) method.

Syntax:

Parameter:

The above requires only one parameter:

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

Return:

The above method is used to return true if the element is already added in the queue. Otherwise, the method returns false.

Throw:

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

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

Output:

The deque is : [45.6, 23.0, 45.8, 66.9]

Example 2

Test it Now

Output:

The list of the elements is given as : [23, 45, 67, 98]

Example 3

Test it Now

Output:

Java
is
a
secured
language.
The required string is given as : [Java, is, a, secured, language.]
Next TopicJava Deque




Latest Courses