Java ArrayDeque - offer() Method
The java.util.ArrayDeque.offer() method is used to add the specified element at the end of the deque.
Syntax
public boolean offer(E element)
Here, E is the type of element maintained by the container.
Parameters
element |
Specify element which need to be added in the deque. |
Return Value
true.
Exception
NA
Example:
In the example below, the java.util.ArrayDeque.offer() method is used to add 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 offer method MyDeque.offer(10); MyDeque.offer(20); MyDeque.offer(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