Difference Between Java's PriorityQueue and Min Heap

Oh, I see what you’re getting at! Yes, Java’s PriorityQueue is essentially a java min heap in its default form. But the naming can be a bit tricky. The PriorityQueue is backed by a binary heap (a java min heap by default), and when you add elements, the one with the smallest value (according to natural ordering or a comparator) gets dequeued first.

So why is it called PriorityQueue and not just a heap? Well, it’s designed to serve the purpose of a priority queue — meaning that elements are removed based on priority, not just order. The PriorityQueue abstracts that behavior using the heap structure underneath. So in simple terms, while a heap is the technical structure, a priority queue is the intended use case.