/**

mapKey 主键key

**/

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

posted on 2022-12-23 14:12  橙子加西瓜  阅读(20)  评论(0编辑  收藏  举报