1. PriorityQueue does NOT permit insertion of non-comparable objects (doing so may result in ClassCastException).
2. The Iterator provided in method iterator() is NOT guaranteed to traverse the elements of the PriorityQueue in any particular order.
If you want selecting or printing elements from PriorityQueue in order according their priority, use peek() or poll() method.
Printing PriorityQueue elements with Iterator or like in your example only using
does not guarantee ordering.
It means our mission is in jeapordy! Quick, read this tiny ad!
a bit of art, as a gift, that will fit in a stocking