当前位置: 代码迷 >> 综合 >> List list按某些字段排序
  详细解决方案

List list按某些字段排序

热度:17   发布时间:2024-01-27 06:42:21.0
    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;}}});}
  相关解决方案