I have a doubt about when exactly does 'natural ordering' take place in a PriorityQueue. Have a look at the following code:
[arrow, pink, ball]
My question is when I printed pq, the result I get is not ordered, however printing pq after invoking the poll method seems to give me an ordered result of the remaining two elements. This seem to imply that ordering took place
only after the poll method was invoked. However, if I were to replace the poll method with a peek and than print pq, the result I get is the same as the first print statement: [arrow, pink, ball] and not [arrow, ball, pink] as I was expecting after observing what happened after the poll() method. Why this difference? does ordering take place only after poll() gets invoked? Hope someone can explain. Thank you.