import com.it.vo.Student; import java.util.ArrayList; import java.util.List; /** * anyMatchPredicate p) 传入一个断言型函数,对流中所有的元素进行判断, * 只要有一个满足条件就返回true,都不满足返回false。 */ public class Test { public static void mainString [] args) { Student stu1 = new Student01, 19, "张三"); Student stu2 = new Student02, 23, "李四"); Student stu3 = new Student01, 28, "王五"); List<Student> list = new ArrayList<>); list.addstu1); list.addstu2); list.addstu3); // 判断学生年龄是否有大于27岁的 boolean anyMatchFlag = list.stream).anyMatchstudent -> student.getAge) > 27); System.out.printlnanyMatchFlag); } }
//结果:true