降序:
static class MapComparatorDesc implements Comparator<Map<String, Object>> {
@Override
public int compare(Map<String, Object> m1, Map<String, Object> m2) {
Double v1 = Double.valueOf(m1.get("avgScore").toString());
Double v2 = Double.valueOf(m2.get("avgScore").toString());
if (v2 != null) {
return v2.compareTo(v1);
}
return 0;
}
}
升序:
static class MapComparatorAsc implements Comparator> {
@Override
public int compare(Map m1, Map m2) {
Doublev1 = Double.valueOf(m1.get("avgScore").toString());
Doublev2 = Double.valueOf(m2.get("avgScore").toString());
if(v1 != null){
return v1.compareTo(v2);
}
使用:
Collections.sort(mapList, new MapComparatorDesc());
相关文章
暂无评论...