Queue
A queue is a linear data structure that follows the FIFO (First In, First Out) principle: the element added first is the first one removed. Elements are added at the rear (enqueue) and removed from the front (dequeue).
Queues are used for task scheduling, print jobs, handling requests in order, message brokers and breadth-first search. Variants include circular queues, priority queues and double-ended queues (deques).
import java.util.ArrayDeque;
import java.util.Queue;
Queue<String> queue = new ArrayDeque<>();
queue.offer("first");
queue.offer("second");
System.out.println(queue.poll()); // first (first in, first out)
System.out.println(queue.peek()); // second