根据map中的value值进行排序
public void test(Map<String, Integer> map){
List<Entry<String, Integer>> list = new ArrayList<Entry<String, Integer>>(map.entrySet());
Collections.sort(list,new Comparator<Entry<String, Integer>>() {
@Override
public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
//从大到小,若从小到大则反过来即可
return (o2.getValue()-o1.getValue());
}
});
}
注:如有错误,欢迎指正,谢谢!