import java.util.*; class Priority{ public static void main(String args[]){ PriorityQueue queue=new PriorityQueue(); queue.add(\"Amit\
This question is answered in the Javadoc:
The Iterator provided in method iterator() is not guaranteed to traverse the elements of the priority queue in any particular order.
To traverse the PQ in sorted order you have to use the remove() method.
remove()