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<Student> 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);
}
}
allMatch用法
最新推荐文章于 2025-06-26 21:20:09 发布
4万+

被折叠的 条评论
为什么被折叠?



