Question:I want to loop through a
PriorityQueue, and wondering if following
iterator()is the best way
I don’t care about the queue afterwards, so another way would be to use
!queue.isEmpty()but the time complexity would be O(logn).
Answer:If you want ordered retrieval of your elements, you must poll/remove elements from the queue; using iterator will not be enough.
If you have better answer, please add a comment about this, thank you!