Iterating over a PriorityQueue is NOT ordered April 11, 2011 / Dave / 0 Comments I stumbled across a little Java gotcha recently when trying to order a collection of Java objects. For some reason I decided to use a PriorityQueue because I wanted to maintain duplicates, so TreeSet and TreeMap were ruled out. Unfortunately, the PriorityQueue is only ordered when remove/peek/poll-ing objects from the collection. NOT when iterating over the collection. This fun fact is clearly identified in the PriorityQueue JavaDocs :
Read full article from Iterating over a PriorityQueue is NOT ordered | dpdearing
No comments:
Post a Comment