I want to sort map in descending order by value and print only key having highest value Note: print multiple key if both have same value
map.put(5,3); map.put(4,1); map.put(2,2); map.put(10,3); Set <Map.Entry<Integer,Integer>>set = map.entrySet(); List <Map.Entry<Integer,Integer>> list = new ArrayList<Map.Entry<Integer,Integer>>(set); Collections.sort(list, new Comparator<Map.Entry<Integer,Integer>>(){ public int compare(Map.Entry<Integer,Integer> obj1, Map.Entry<Integer,Integer> obj2){ return (obj2.getValue().compareTo(obj1.getValue())); } }); Now i got output 5,10 but i want output as 10,5