java List<Map> 排序问题

 Collections.sort(order_from_list, new Comparator<Map<Object, Object>>() {
            public int compare(Map<Object, Object> o1, Map<Object, Object> o2) {
                int map1value = (Integer) o1.get("pkey");
                int map2value = (Integer) o2.get("pkey");
                return map1value - map2value;
            }
        });

(二)

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
public class $ {
    public static void main(String[] args) {
        List<Map<String, String>> list = new ArrayList<Map<String, String>>();
 
        list.add(getData(0));
        list.add(getData(3));
        list.add(getData(05));
        list.add(getData(6));
        list.add(getData(2));
 
        System.out.println("排序前" + list);
 
        Collections.sort(list, new Comparator<Map<String, String>>() {
            public int compare(Map<String, String> o1, Map<String, String> o2) {
                return o1.get("countScore").compareTo(o2.get("countScore"));
            }
        });
 
        System.out.println("排序后" + list);
    }
 
    private static Map<String, String> getData(int num) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("countScore", String.valueOf(num));
        return map;
    }
}

List list;想根据pkey大小排序,我写这个它报了类型不匹配,

   list格式:
    [
{
    stype=source_from,
    pkey=132,
    pname=BJ,
    codea=,
    codeb=,
    codec=,
    coded=,
    codee=,
    dflag=,
    sortby=2,
    vflag=add,
    comments=来源,
    source_from=SS
},
{
    stype=source_from,
    pkey=134,
    pname=DD,
    codea=,
    codeb=,
    codec=,
    coded=,
    codee=,
    dflag=,
    sortby=0,
    vflag=add,
    comments=来源,
    source_from=ECS
}
]

 

posted @ 2016-10-25 18:49  龙昊雪  阅读(20887)  评论(0编辑  收藏  举报