I want to sort the values in in ascending order by values of HashMap in Priority Queue.
HashMap<Integer, Integer> map = new HashMap<>();
map.put(1, 1);
map.put(2, 5);
map.put(3, 2);
map.put(4,4);
PriorityQueue<Map.Entry<Integer,
Integer>> minHeap
= new PriorityQueue<>(
(a, b)
-> a.getValue().equals(b.getValue())
? Integer.compare(a.getKey(),
b.getKey())
: Integer.compare(a.getValue(),
b.getValue()));
for(Map.Entry<Integer,Integer> entry:map.entrySet()){
minHeap.add(entry);
}
System.out.println(minHeap);
Output [1=1, 4=4, 3=2, 2=5]
Can anyone suggest why the order is not coming in ascending order by values