From the Javadoc of its
iterator() method, which is used internally when printing:
Returns an iterator over the elements in this queue. The iterator does not return the elements in any particular order.
This is also said in the class' main Javadoc:
he Iterator provided in method iterator() is not guaranteed to traverse the elements of the priority queue in any particular order. If you need ordered traversal, consider using Arrays.sort(pq.toArray()).
.
The priority is only guaranteed for
poll(),
peek(),
remove() and
element().