java8 lambda表达式根据id组合两个LIst

List list1 =  new ArrayList<>();
List list2 =  new ArrayList<>();
List collection =  new ArrayList<>();
collection  = 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());

 

你可能感兴趣的:(java)