Java ArrayDeque - addLast() Method
The java.util.ArrayDeque.addLast() method is used to add a new element at the end of the deque. This method is equivalent to add method of the ArrayDeque.
Syntax
public void addLast(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
void type.
Exception
Throws NullPointerException, if the specified element is null.
Example:
In the example below, the java.util.ArrayDeque.addLast() method is used to add new element at the end 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 addLast() method MyDeque.addLast(10); MyDeque.addLast(20); MyDeque.addLast(30); MyDeque.addLast(100); MyDeque.addLast(200); //printing ArrayDeque System.out.println("MyDeque contains: " + MyDeque); } }
The output of the above code will be:
MyDeque contains: [10, 20, 30, 100, 200]
❮ Java.util - ArrayDeque