List<Map<String,Object>> map1 = null;
List<Map<String,Object>> map2 = null;
for (Map<String, Object> x : map1) {
for (Map<String, Object> y : map2) {
if (x.get("id").equals(y.get("id"))){
//todo
}
}
}
类似这种用java8的Stream如何操作呢
2 回答
慕码人2483693
TA贡献1860条经验 获得超9个赞
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
});
你试试这个呢
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());
添加回答
举报
0/150
提交
取消