排序

//降序
public static List<Map.Entry<String, Double>> getDescSortMap(Map<String, Double> valueMap) {
List<Map.Entry<String, Double>> entryList = new ArrayList<>(valueMap.entrySet());
Collections.sort(entryList,
new Comparator<Map.Entry<String, Double>>() {
public int compare(Map.Entry<String, Double> entry1,
Map.Entry<String, Double> entry2) {
return entry2.getValue().compareTo(entry1.getValue());
}
});
return entryList;
}

//升序
public static List<Map.Entry<String, Double>> getAscSortMap(Map<String, Double> valueMap) {
List<Map.Entry<String, Double>> entryList = new ArrayList<>(valueMap.entrySet());
Collections.sort(entryList,
new Comparator<Map.Entry<String, Double>>() {
public int compare(Map.Entry<String, Double> entry1,
Map.Entry<String, Double> entry2) {
return entry1.getValue().compareTo(entry2.getValue());
}
});
return entryList;
}
posted @ 2016-06-06 11:53  晨曦的小尾巴  阅读(96)  评论(0)    收藏  举报