Hi Team,
Im reading Collections. It is mentioned that while intialising priority queue, it uses natural ordering by default.
But my output is not like that. Below is my code and output.
public class BackedCollections {
public static void main(String[] args) {
PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
pq.offer(3);
pq.offer(1);
pq.offer(5);
pq.offer(2);
pq.offer(12);
pq.offer(14);
pq.offer(0);
System.out.println(pq);
}
}
** OUTPUT **
[0, 2, 1, 3, 12, 14, 5]
It Should be [0,1,2,3,5,12,15] right ? Please clarify