根據Map值 double 類型的進行排序


/**
* 將集合按照降序排列-Double
* @param nowPartTwoData
* @return
*/
private static List<Map<String,Double>> sortByValueFloatDesc(Map<String, Double> nowPartTwoData) {
List<Map.Entry<String, Double>> lists = new ArrayList<Map.Entry<String, Double>>(nowPartTwoData.entrySet());
Collections.sort(lists, new Comparator<Map.Entry<String, Double>>() {
public int compare(Map.Entry<String, Double> o1, Map.Entry<String, Double> o2) {
Double q1 = Double.parseDouble(o1.getValue()+"");
Double q2 = Double.parseDouble(o2.getValue()+"");
Double p = q2 - q1;
if (p > 0) {
return 1;
} else if (p == 0) {
return 0;
} else
return -1;
}
});
for (Map.Entry<String, Double> set : lists) {
System.out.println(set.getKey() + " " + set.getValue());
}
return null;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM