Sitemap
Dinuka Kasun Medis

Dinuka Kasun Medis

Turning complex code into simple ideas. Exploring Java, Spring Boot, system design, and the craft of building reliable software that makes a difference. 🚀

Member-only story

Java Queue vs Deque vs PriorityQueue: Differences and Examples

4 min readOct 14, 2026

--

Think about ticket line, two-door bus, emergency room. Three pictures, three behaviors. All three types hold items and hand them back one at a time. The only difference is which item comes out next:

  • Queue: the one that arrived first
  • Deque: the one at whichever end you choose
  • PriorityQueue: the most important one
Collection
└── Queue
├── Deque
│ └── ArrayDeque, LinkedList
└── PriorityQueue

Remember: Deque extends Queue, so a Deque can do everything a Queue does, plus more.

Remember It as Three Places

  • Ticket line = Queue. First in, first out (FIFO).
  • Two-door bus = Deque. Add and remove at both ends.
  • Emergency room = PriorityQueue. Most urgent first, not first come.”
Press enter or click to view image in full size
Queue waits, Deque doubles, PriorityQueue prioritizes.

Queue: First In, First Out

Queue<String> queue = new ArrayDeque<>();
queue.offer("Write report");
queue.offer("Fix bug");
queue.offer("Send email");

System.out.println(queue.poll()); // Write report
System.out.println(queue.poll()); // Fix bug

The first item added is the first item removed.

--

--

Dinuka Kasun Medis
Dinuka Kasun Medis

Written by Dinuka Kasun Medis

Turning complex code into simple ideas. Exploring Java, Spring Boot, system design, and the craft of building reliable software that makes a difference. 🚀