List<Map<Object, Object>> list1 = new ArrayList<>();
List<Map<Object, Object>> list2 = new ArrayList<>();
list1.stream()
.filter(map -> list2.stream().anyMatch(map1 -> map.get("id").equals(map1.get("id"))))
.forEach(map -> {
// to do sth
});
你試試這個(gè)呢
List<Map<Object, Object>> list3 = list1.stream()
.map(map -> list2.stream()
.filter(m -> Objects.equals(m.get("id"), map.get("id")))
.findFirst().map(m -> {
map.putAll(m);
return map;
}).orElse(null))
.filter(Objects::nonNull).collect(Collectors.toList());
|