Map map = new TreeMap();
map.put("j2se", 20);
map.put("j2ee", 10);
map.put("j2me", 30);
List> infoIds = new ArrayList>(
map.entrySet());
//排序前
for (int i = 0; i < infoIds.size(); i++) {
String id = infoIds.get(i).toString();
System.out.println(id);
}
//排序
Collections.sort(infoIds, new Comparator>() {
public int compare(Map.Entry o1,
Map.Entry o2) {
return (o2.getValue() - o1.getValue());
}
});
//排序后
for (int i = 0; i < infoIds.size(); i++) {
String id = infoIds.get(i).toString();
System.out.println(id);
}
排序前:
j2ee=10
j2me=30
j2se=20
排序后:
j2me=30
j2se=20
j2ee=10
分享到:
2010-01-03 18:56
浏览 7336
评论
2 楼
xiaobadi
2012-09-26
1 楼
niuqiang2008
2011-02-23
楼主可以继续讲吗!