I don't understand the following behaviour of Java. The following code:
Queue<Integer> minQueue = new PriorityQueue<>((a, b) -> a - b);
Queue<Integer> maxQueue = new PriorityQueue<>((a, b) -> b - a);
minQueue.offer(3);
minQueue.offer(1);
minQueue.offer(5);
minQueue.offer(4);
System.out.println(minQueue);
maxQueue.offer(3);
maxQueue.offer(1);
maxQueue.offer(5);
maxQueue.offer(4);
System.out.println(maxQueue);
This results in
[1, 3, 5, 4]
[5, 4, 3, 1]
But why does the first one not result in [1, 3, 4, 5]
?