方法一
ArrayList studentArrayList = new ArrayList<>();
studentArrayList.add(new Student("zhangsan",12,98,"优等生"));
studentArrayList.add(new Student("lisi",13,75,"还不错"));
studentArrayList.add(new Student("wangwu",14,58,"别上了"));
studentArrayList.add(new Student("zaoliu",15,60,"就那样"));
studentArrayList.add(new Student("tianqi",15,89,"还不错"));
System.out.println(studentArrayList.stream().map(Student::getScore).max((x1, x2) ->x1.compareTo(x2)).get());
System.out.println(studentArrayList.stream().map(Student::getScore).min((x1, x2) -> x1.compareTo(x2)).get());
方法二
在这里插入代码片ArrayList studentArrayList = new ArrayList<>();
studentArrayList.add(new Student("zhangsan",12,98,"优等生"));
studentArrayList.add(new Student("lisi",13,75,"还不错"));
studentArrayList.add(new Student("wangwu",14,58,"别上了"));
studentArrayList.add(new Student("zaoliu",15,60,"就那样"));
studentArrayList.add(new Student("tianqi",15,89,"还不错"));
Student max=studentArrayList.get(0);
for (Student student : studentArrayList) {
if (student.getScore()>max.getScore()){
int score = student.getScore();
max.setScore(score);
}
}
System.out.println(max.getScore());