Java 8 Lambda filter by Lists

前端 未结 4 1082
生来不讨喜
生来不讨喜 2020-12-08 02:15

I have two list and i want filter thoose elements which are both list contains. And i want to do this with lambda expression.

Users getName and Clients getUserName b

4条回答
  •  猫巷女王i
    2020-12-08 02:49

    Look this:

    List result = clients
        .stream()
        .filter(c -> 
            (users.stream().map(User::getName).collect(Collectors.toList())).contains(c.getName()))
            .collect(Collectors.toList());
    

提交回复
热议问题