I meet a problem about order of PriorityQueue in Java 8, Intellij Idea, when I add the third number in the queue, the order is wrong, but only the third one have this probl
PriorityQueue's implementation is a priority heap implementation & not sorted list.
The Iterator provided in method iterator() is not guaranteed to traverse the elements of the priority queue in any specific order. If you need ordered traversal, use something like:
Arrays.sort(q.toArray());
for (Integer data :q) {
System.out.println(data);
}