Filtering a list of JavaBeans with Google Guava

前端 未结 9 741
夕颜
夕颜 2020-12-01 06:59

In a Java program, I have a list of beans that I want to filter based on a specific property.

For example, say I have a list of Person, a JavaBean, where Person has

9条回答
  •  一向
    一向 (楼主)
    2020-12-01 07:19

    With Java8 style you can use stream + filter to achieve your goal.

    persons.stream()
                .filter(p -> names.contains(p.getName()))
                .collect(Collectors.toList());
    

提交回复
热议问题