Without providing custom comparator the priority queue inserts elements in ascending order, however, after removing a particular element the order is changed.
PriorityQueue<Integer> pq = new PriorityQueue<>();
pq.add(10);
pq.add(1);
pq.add(2);
pq.add(2);
pq.remove(2);
for(int x: pq) {
System.out.println(x);
}
//outputs: 1 10 2, instead of expected: 1 2 10
Any ideas?
Thanks.

