Created
July 7, 2021 05:32
-
-
Save cankush625/13dbba61eaf5621bb2ad7166c623dd3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private HashMap<Integer, Integer> sortByValueAscending(HashMap<Integer, Integer> numCounts) { | |
List<Map.Entry<Integer, Integer> > list = | |
new LinkedList<Map.Entry<Integer, Integer> >(numCounts.entrySet()); | |
Collections.sort(list, new Comparator<Map.Entry<Integer, Integer> >() { | |
public int compare(Map.Entry<Integer, Integer> o1, | |
Map.Entry<Integer, Integer> o2) | |
{ | |
return (o1.getValue()).compareTo(o2.getValue()); | |
} | |
}); | |
HashMap<Integer, Integer> temp = new LinkedHashMap<Integer, Integer>(); | |
for (Map.Entry<Integer, Integer> aa : list) { | |
temp.put(aa.getKey(), aa.getValue()); | |
} | |
return temp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment