Queue is a linear data structure that follows FIFO (First In, First Out).
It’s part of the Java Collection Framework via the Queue interface.

Deque (double-ended queue) allows insertion and removal from both ends - supports both FIFO and LIFO operations.

Common Implementations

InterfaceClassBehavior
QueueLinkedListFIFO
QueuePriorityQueueSorted by priority (natural/custom)
DequeArrayDequeResizable array-based deque
DequeLinkedListDoubly-linked list

Example

Basic Queue
Queue<String> queue = new LinkedList<>();
queue.add("A");
queue.add("B");
 
System.out.println(queue.poll()); // "A"
System.out.println(queue.poll()); // "B"
 
// add() / offer() to enqueue
// poll() / remove() to dequeue
PriorityQueue
Queue<Integer> pq = new PriorityQueue<>();
pq.add(3);
pq.add(1);
pq.add(2);
 
System.out.println(pq.poll()); // 1 (natural order)
Deque
Deque<String> deque = new ArrayDeque<>();
deque.addFirst("A");
deque.addLast("B");
 
System.out.println(deque.removeFirst()); // A
System.out.println(deque.removeLast());  // B

Comparison

Queue vs Deque

FeatureQueueDeque
DirectionOne-way (FIFO)Two-way (FIFO + LIFO)
InterfacesQueueDeque
Common ClassLinkedListArrayDeque, LinkedList

Real-World Analogy

Queue: line at a coffee shop (first come, first served).
Deque: double-ended elevator (can load/unload from both ends).

Tip

Be ready to:

  • choose between Queue, Deque and Stack,
  • use ArrayDeque for efficient stack/queue operations (better than Stack/LinkedList),
  • explain when you’d use PriorityQueue (e.g. Dijkstra’s algorithm, task scheduling).

Parent: _Collections