Queue and Deque
Queue is first in first out and Deque works at both ends. ArrayDeque is the usual choice.
Example
import java.util.*;
public class Main {
public static void main(String[] args) {
Deque<Integer> d = new ArrayDeque<>();
d.addLast(1); d.addLast(2); d.addFirst(0);
System.out.println(d + " " + d.pollFirst() + " " + d.peekLast());
}
}Result
[0, 1, 2] 0 2
Exercise
Add to the front.
d.(0)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.