0
0

More than 1 year has passed since last update.

Queue , Deque class

Last updated at Posted at 2023-02-10

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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0