The Java Doc says: Creates a PriorityQueue with the default initial capacity (11) that orders its elements according to their natural ordering.
but when I write some test like this:
public class Test {
public static void main (String a[]) {
Queue<Integer> queue = new PriorityQueue<Integer>();
for (int i = 1; i <= 20; i++) {
queue.offer(i);
}
System.out.println(queue);
Queue<Integer> queue2 = new PriorityQueue<Integer>();
for (int i = 20; i >= 1; i--) {
queue2.offer(i);
}
System.out.println(queue2);
}
}
I got following output:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
[1, 2, 7, 4, 3, 10, 8, 11, 5, 12, 13, 19, 15, 16, 9, 20, 14, 17, 6, 18]
Seenm like two queue with the same content, their content did not get same order?