Intersection and union of ArrayLists in Java

后端 未结 24 2489
离开以前
离开以前 2020-11-22 06:05

Are there any methods to do so? I was looking but couldn\'t find any.

Another question: I need these methods so I can filter files. Some are AND filter

24条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 06:37

    Intersection of two list of different object based on common key - Java 8

     private List intersection(List users, List list) {
    
            return list.stream()
                    .flatMap(OtherUser -> users.stream()
                            .filter(user -> user.getId()
                                    .equalsIgnoreCase(OtherUser.getId())))
                    .collect(Collectors.toList());
        }
    

提交回复
热议问题