Map根据Value排序
public static Map<String, Double> sortMapByValue(Map<String, Double> oriMap) {
if (oriMap == null || oriMap.isEmpty()) {
return null;
}
Map<String, Double> sortedMap = new LinkedHashMap<String, Double>();
List<Map.Entry<String, Double>> entryList = new ArrayList<Map.Entry<String, Double>>(
oriMap.entrySet());
Collections.sort(entryList, new MapValueComparator());
Iterator<Map.Entry<String, Double>> iter = entryList.iterator();
Map.Entry<String, Double> tmpEntry = null;
while (iter.hasNext()) {
tmpEntry = iter.next();
sortedMap.put(tmpEntry.getKey(), tmpEntry.getValue());
}
return sortedMap;
}
class MapValueComparator implements Comparator<Map.Entry<String, Double>> {
public int compare(Map.Entry<String, Double> me1, Map.Entry<String, Double> me2) {
return me1.getValue().compareTo(me2.getValue());
}
}