##Hashmap in java, specifiy the Comparator
1 |
|
This is to define the sort algorithm,1
2
3
4
5class ComparatorImpl implements Comparator<Map.Entry<Character,Integer>>{
public int compare(Map.Entry<Character,Integer> a ,Map.Entry<Character,Integer> b){
return b.getValue() - a.getValue();
}
}
1 convert the hash Entry to array list, and sort.
2 there is other way, such as TreeSet