Java.Collections.Which collection implements the FIFO maintenance discipline?

Queue — and its common implementations — are designed to follow the FIFO order.


✅ The Main FIFO Collection in Java: Queue

Java’s Queue interface (from java.util) is specifically designed for FIFO behavior, where:

The first element added is the first one removed.

📦 Common FIFO Implementations:

ClassDescription
LinkedList✅ Implements Queue and maintains FIFO order
ArrayDeque✅ A fast, resizable array-based queue (double-ended)
PriorityQueue❌ Not FIFO — ordered by priority, not insertion
ConcurrentLinkedQueue✅ Thread-safe FIFO queue
LinkedBlockingQueue✅ FIFO queue from java.util.concurrent for multithreading

🧪 FIFO Example using LinkedList as a Queue:

Queue<String> queue = new LinkedList<>();

queue.add("A");
queue.add("B");
queue.add("C");

System.out.println(queue.poll()); // A
System.out.println(queue.poll()); // B
System.out.println(queue.poll()); // C

poll() removes the head of the queue (first-in element).

This entry was posted in Без рубрики. Bookmark the permalink.