Stream流中filter方法

Stream流中filter方法

  • 一、filter方法


一、filter方法

  Stream<T> filter(Predicate<? super T> predicate);

    @Test
    void test9() {
        List<People> peopleList = new ArrayList<>();
        peopleList.add(new People(1, "小王", 1));
        peopleList.add(new People(2, "小李", 2));
        peopleList.add(new People(3, "小张", 2));
        peopleList.add(new People(4, "小皇", 1));

        Stream<People> peopleStream = peopleList.stream().filter(s -> {
            if (s.getJgid() % 2 != 0) {
                return false;
            } else {
                return true;
            }

        });

        peopleStream.forEach(System.out::println);
    }

在这里插入图片描述

你可能感兴趣的:(java常规,java,开发语言)