public void listSort(List<Map<String, Object>> list) throws Exception {
// list是需要排序的list,其内放的是Map
// 返回的结果集
Collections.sort(list, new Comparator<Map<String, Object>>() {
public int compare(Map<String, Object> o1, Map<String, Object> o2) {
// o1,o2是list中的Map,可以在其内取得值,按其排序,此例为升序,s1和s2是排序字段值
Integer s1 = (Integer) o1.get("sequence");
Integer s2 = (Integer) o2.get("sequence");
if (s1 > s2) {
return 1;
} else {
return -1;
}
}
});
}