public static ArrayList<Map.Entry<String, Integer>> getSortedHashMapByValue(Map<String, Integer> map) {
ArrayList<Map.Entry<String, Integer>> entries = new ArrayList<Map.Entry<String, Integer>>(map.entrySet());
Collections.sort(entries, new Comparator<Map.Entry<String, Integer>>() {
@Override
public int compare(Entry<String, Integer> o1,
Entry<String, Integer> o2) {
Integer key1 = o1.getValue();
Integer key2 = o2.getValue();
return key1.compareTo(key2);
}
});
return entries;
}
ArrayList<Map.Entry<String, Integer>> entries = new ArrayList<Map.Entry<String, Integer>>(map.entrySet());
Collections.sort(entries, new Comparator<Map.Entry<String, Integer>>() {
@Override
public int compare(Entry<String, Integer> o1,
Entry<String, Integer> o2) {
Integer key1 = o1.getValue();
Integer key2 = o2.getValue();
return key1.compareTo(key2);
}
});
return entries;
}