对Map的key按升序进行排序

//对Map的key按升序进行排序
List<Map.Entry<Integer,Task>> mappingList = new ArrayList<Map.Entry<Integer, Task>>(map.entrySet());
Collections.sort(mappingList, new Comparator<Map.Entry<Integer, Task>>() {
@Override
public int compare(Entry<Integer, Task> o1, Entry<Integer, Task> o2) {
return o1.getKey().compareTo(o2.getKey());
}
});
for (Map.Entry<Integer, Task> mapping : mappingList) {
result.add(mapping.getValue());
}

 

posted on 2017-04-10 18:16  神啊bin  阅读(642)  评论(0编辑  收藏  举报

导航