Create DeQue in Java - How to add Elements to DeQue

Published April 04, 2022

An array Deque can easily be created in Java. You only need to import the java.util.ArrayDeque package. After import, create the array Deque as follows:

ArrayDeque<Type> name_of_array_Deque = new ArrayDeque<>();


You can create either a string or an integer ArrayDeque. For instance

// A String type 

ArrayDeque<String> students = new ArrayDeque<>();

// Integer type 

ArrayDeque<Integer> marks = new ArrayDeque<>();



Example of an ArrayDeque Program

For this example, we will create an ArrayDeque and add three students by using the add(), addFirst(), and addLast() methods.


import java.util.ArrayDeque;

public class ArrayDequeClass {

    public static void main(String[] args) {

        ArrayDeque<String> students= new ArrayDeque<>();

        // Add first student using add()


        // Add second student using addFirst()


        // Add third student using addLast()


        System.out.println("ArrayDeque: " + students);





ArrayDeque: [Rohit, Rajkmaar, Thakur]

Article Contributed By :