Map的键排序(java)
解决方法:
Map<String,Integer> idsMap=new HashMap<String,Integer>();
List<Map.Entry<String,Integer>> list2 = new ArrayList<Map.Entry<String,Integer>>(idsMap.entrySet());
Collections.sort(list2,new Comparator<Map.Entry<String,Integer>>() {
public int compare(Entry<String, Integer> o1,
Entry<String, Integer> o2) {
// 降序
return o2.getValue().compareTo(o1.getValue());
// 升序
//return o2.getValue().compareTo(o1.getValue());
}
});
对map的键key进行排序请参考:http://www.yayihouse.com/yayishuwu/chapter/1816