allMatch用法

import com.it.vo.Student;
import java.util.ArrayList;
import java.util.List;

/**
 * 方法allMatch(Predicate p) 传入一个断言型函数,
 * 对流中所有的元素进行判断,如果都满足返回true,
 * 否则返回false。
 */
public class Test {
    public static void main(String [] args) {
        Student stu1 = new Student(01, 19, "张三");
        Student stu2 = new Student(02, 23, "李四");
        Student stu3 = new Student(01, 28, "王五");
        List list = new ArrayList<>();
        list.add(stu1);
        list.add(stu2);
        list.add(stu3);
        //判断学生年龄是否都大于18
        boolean flag = list.stream().allMatch(stu -> stu.getAge() > 18);
        System.out.println(flag);
    }
}

你可能感兴趣的:(03,集合)