This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Good Reason to be confused. Priority queue is implemented as Heap data structure. I do not know the exact details of the implementation. But with a min heap structure only one thing is assured, root has the minimum.
So after you poll the order you get 1, 2, 3, 4, 5 is pure coincidence. It could have been in any order with 1 as the root (first element).
Still confusing 1. read about heaps 2. Read how heaps are impemented in a queue 3. Look at priorityqueue fixup method.