Queue performs FIFO(First In First Out) Queue
Deque is Double ended Queue. we can use addFirst or addLast to DeQueue.
public class Outer {
public static void main(String args[]) {
Queue<Integer> q = new ArrayDeque<>();
q.add(1);
q.add(2);
q.add(3);
q.forEach(System.out::println);
}
}
1
2
3
public class Outer {
public static void main(String args[]) {
Deque<Integer> q = new ArrayDeque<>();
q.add(1);
q.add(2);
q.add(3);
q.addFirst(98);
q.addFirst(99);
q.addLast(5);
q.addLast(6);
q.forEach(System.out::println);
}
}
99
98
1
2
3
5
6