我们有个需求,把包含某些属性的集合给过滤出来,我现在需要把人员编号为1,2,3,4,5的人员过滤出来。
List<Person> personList = new ArrayList<>();
personList.add(new Person(1,"宋圆圆",25,"技术总监"));
personList.add(new Person(2,"李师师",23,"技术专家"));
personList.add(new Person(3,"柳如是",22,"产品经理"));
personList.add(new Person(4,"苏小小",25,"人事主管"));
personList.add(new Person(5,"董小宛",25,"财务总监"));
personList.add(new Person(6,"卞玉京",25,"技术专家"));
List<Integer> id = Arrays.asList(1, 2, 3, 4, 5);
List<Person> list = personList.stream().filter(s -> id.contains(s.getId())).collect(Collectors.toList());
list.forEach(System.out::println);