TreeMap排序
2020-06-10 本文已影响0人
抄无止境
Map<String, Long> energyMap= new TreeMap<String, Long>();
List<Map.Entry<String, Double>> energyMapList = new ArrayList<Map.Entry<String, Double>>(energyMap.entrySet());
Collections.sort(energyMapList, new Comparator<Map.Entry<String, Double>>() {
@Override
public int compare(Map.Entry<String, Double> o1, Map.Entry<String, Double> o2) {
return o2.getValue().compareTo(o1.getValue());
}
});