将两个ListMap中同下标的map去重合并

时间:2024-04-15 08:29:19
public static void main(String[] args) {
        
        Map<String,Object> oneMap = new HashMap<>();
        oneMap.put("key","001");
        oneMap.put("name","张飞");
        oneMap.put("age","25");

        Map<String,Object> twoMap = new HashMap<>();
        twoMap.put("key","001");
        twoMap.put("School","桃园");
        twoMap.put("age","25");

        List<Map<String,Object>> listA = new ArrayList<>();
        listA.add(0,oneMap);

        List<Map<String,Object>> listB = new ArrayList<>();
        listB.add(0,twoMap);

        listA.forEach(a -> {
            listB.forEach(b -> b.putAll(a));
        });

        listB.forEach(b -> b.entrySet().forEach(e -> System.out.println(e.getValue())));
        
    }