public void listSort(List<Map<String,Object>> resultList) throws Exception{ |
// resultList是需要排序的list,其内放的是Map |
// 返回的结果集 |
Collections.sort(resultList, new Comparator<Map<String,Object>>() { |
public int compare(Map<String, Object> o1,Map<String, Object> o2) { |
//o1,o2是list中的Map,可以在其内取得值,按其排序,此例为升序,s1和s2是排序字段值 |
double s1 = Double.parseDouble(o1.get( "value" ).toString()); |
double s2 = Double.parseDouble(o2.get( "value" ).toString()); |
if (s1>s2) { |
return - 1 ; |
} else { |
return 1 ; |
} |
} |
}); |
} |
by: 发表于:2017-06-27 15:24:36 顶(0) | 踩(0) 回复
??
回复评论