以Map为例,使用Collections.sort()方法
List<Map.Entry<Character, Integer>> list = new ArrayList<Map.Entry<Character, Integer>>(charCount.entrySet()); Collections.sort(list, new Comparator<Map.Entry<Character, Integer>>() { // 降序排序 public int compare(Map.Entry<Character, Integer> o1, Map.Entry<Character, Integer> o2) { //return o1.getValue().compareTo(o2.getValue()); return o2.getValue().compareTo(o1.getValue()); } });