List排序

来源:互联网 发布:人工智能电影特点评价 编辑:程序博客网 时间:2024/06/06 22:12
List<Map<String,Object>> list = new ArrayList<Map<String,Object>>(); 
Collections.sort(list, new Comparator<Map<String,Object>>(){                public int compare(Map<String, Object> o1, Map<String, Object> o2)              {               int b1 = (Integer) o1.get("items_sold");             int b2 = (Integer)o2.get("items_sold");               if (b1>b2) {                   return -1;               }else if(b1==b2){               return 0;               }else{               return 1;               }            }                        });  
当List中是个Map,new Comparator时也要加上,否则参数类型不匹配。
0 0
原创粉丝点击