根据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