数据: List< Student > studentList;
- By enhancing the for loop
for (Student student : studentList) {
System.out.println(student);
}
- Traverse through stream
//@FunctionalInterface 函数式接口
studentList.stream().forEach(new Consumer<Student>(){
//接收对象 对Student对象的处理
@Override
public void accept(Student student) {
System.out.println(student);
}
});
- Traverse through a functional interface (only one method of a functional interface is called)
// (函数式接口方法声明)->{方法代码}
System.out.println("\n ===函数式接口方法遍历输出 === ");
studentList.stream().forEach(student->{
System.out.println(student);
});