Java ArrayDeque - offerFirst() Method
The java.util.ArrayDeque.offerFirst() method is used to insert the specified element at the front of the deque.
Syntax
public boolean offerFirst(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.offerFirst() method is used to insert the specified element at the front of the 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 offerFirst method MyDeque.offerFirst(10); MyDeque.offerFirst(20); MyDeque.offerFirst(30); //printing ArrayDeque System.out.println("MyDeque contains: " + MyDeque); } }
The output of the above code will be:
MyDeque contains: [30, 20, 10]
❮ Java.util - ArrayDeque