JAVA中对List<map<String,Object>>根据map某个key值从小到大顺序进行排序


public static void main(String[] args)  {
    List> list = new ArrayList>();
    Map map1 = new HashMap();
    map1.put("name", "p");
    map1.put("周", "10");
    Map map2 = new HashMap();
    map2.put("name", "h");
    map2.put("周", "11");
    Map map3 = new HashMap();
    map3.put("name", "f");
    map3.put("周", "12");
    Map map4 = new HashMap();
    map4.put("name", "f");
    map4.put("周", "9");
    Map map5 = new HashMap();
    map5.put("name", "f");
    map5.put("周", "8");
    list.add(map1);
    list.add(map3);
    list.add(map2);
    list.add(map4);
    list.add(map5);
    Collections.sort(list, new Comparator>() {
        public int compare(Map o1, Map o2) {
            Integer name1 = Integer.valueOf(o1.get("周").toString()) ;//name1是从你list里面拿出来的一个
            Integer name2 = Integer.valueOf(o2.get("周").toString()) ; //name1是从你list里面拿出来的第二个name
            return name1.compareTo(name2);
        }
    });
}

输出的结果: