Java ArrayDeque - offerLast() Method
The java.util.ArrayDeque.offerLast() method is used to insert the specified element at the end of the deque.
Syntax
public boolean offerLast(E element)
Here, E is the type of element maintained by the container.
Parameters
element |
Specify element which need to be inserted in the deque. |
Return Value
true.
Exception
NA
Example:
In the example below, the java.util.ArrayDeque.offerLast() method is used to insert the specified element at the end of the given deque.
import java.util.*; public class MyClass { public static void main(String[] args) { //creating a ArrayDeque ArrayDeque<Integer> MyDeque = new ArrayDeque<Integer>(); //populating ArrayDeque using offerLast method MyDeque.offerLast(10); MyDeque.offerLast(20); MyDeque.offerLast(30); //printing ArrayDeque System.out.println("MyDeque contains: " + MyDeque); } }
The output of the above code will be:
MyDeque contains: [10, 20, 30]
❮ Java.util - ArrayDeque