This content has been marked as final. Show 2 replies
The toString() method of a PriorityQueue in no way reflect the order of the elements in the queue. Since the PriorityQueue is based on a 'heap' ( see http://download.oracle.com/javase/6/docs/api/java/util/PriorityQueue.html and http://www.cs.auckland.ac.nz/software/AlgAnim/heaps.html ) the order you see in the toString() is probably the physical order of the elements in the array used to back the 'heap' which is not the logical queue order.
Check the Javadoc. PrioriyQueue only exhibits ordering when you remove fom it.1 person found this helpful