java List<Map> 去重

public static List> removeRepeatMapByKey(List>list, String mapKey){
    if (CollectionUtils.isNullOrEmpty(list)) return null;

    List> listMap = new ArrayList<>();
    Map msp = new HashMap<>();
    for(int i = list.size()-1 ; i>=0; i--){
        Map map = list.get(i);
        String id =  map.get(mapKey).toString();//错误举例 (String)map.get(mapKey);
        map.remove(mapKey);
        msp.put(id, map);
    }
    Set mspKey = msp.keySet();
    for(String key: mspKey){
        Map newMap = msp.get(key);
        newMap.put(mapKey, key);
        listMap.add(newMap);
    }
    return listMap;
}

你可能感兴趣的:(java)