import com.it.vo.Student; import java.util.ArrayList; import java.util.List; /** * anyMatch(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<Student> list = new ArrayList<>(); list.add(stu1); list.add(stu2); list.add(stu3); // 判断学生年龄是否有大于27岁的 boolean anyMatchFlag = list.stream().anyMatch(student -> student.getAge() > 27); System.out.println(anyMatchFlag); } }
//结果:true
最新评论