兩個LIst
public static void main(String[] args) {
Map<String, Object> A1 = new HashMap<>();
A1.put("name", "張三");
A1.put("age", "25");
A1.put("sex", "男");
Map<String, Object> A2 = new HashMap<>();
A2.put("name", "張四");
A2.put("age", "23");
A2.put("sex", "女");
Map<String, Object> B1 = new HashMap<>();
B1.put("name", "張三");
B1.put("age", "25");
B1.put("School", "清華");
Map<String, Object> B2 = new HashMap<>();
B2.put("name", "張四");
B2.put("age", "23");
B2.put("School", "北大");
List<Map<String, Object>> listA = new ArrayList<>();
listA.add(A1);
listA.add(A2);
List<Map<String, Object>> listB = new ArrayList<>();
listB.add(B1);
listB.add(B2);
listA.forEach(d1 -> {
listB.forEach(d2 ->{
if (d1.get("name").toString().equals(d2.get("name").toString())) {
d2.putAll(d1);
}
});
});
}