For this:
PriorityQueue<Integer> pq = new PriorityQueue<>();
pq.add(2);
System.out.println(pq);
pq.add(4);
System.out.println(pq);
pq.add(1);
System.out.println(pq);
I am getting this output:
[2]
[2, 4]
[1, 4, 2]
Why is the output for the third line not [2,4,1]
?