Search code examples
javac++queuedeque

What is the Java equivalent of C++ deque?


in C++ all I had to do was

#include <queue> -> including
queue<int> a; -> defining
a.push(1); ->using

but in java I found very difficult to use simple deque what should I do...? more specifically, How should I code to simply do the same steps as I did in C++; including, defining, using.

even more specifically, I want to make a deque so that I can add any integer in the deque at front or back. and print whole numbers in that deque by the size of the deque


Solution

  • Java has both Queue and Deque types, and a LinkedList, among others, can act as either one:

    import java.util.*;
    Deque<Integer> q = new LinkedList<Integer>();
    q.push(1);