How does Java’s PriorityQueue differ from a min-heap?

Add() works like an insertWithPriority.

You can define priority for the type that you want using the constructor:

PriorityQueue(int, java.util.Comparator)

look under https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/PriorityQueue.html

The order the Comparator gives will represent the priority in the queue.

Leave a Comment