stream之forEach的用法
public static class Student{ private String name; private String sex; private String age; public String getName() { return name; } public void setName(String name) { this.name = name; } public static void main(String[] args) { Student student = new Student(); student.setName("张三"); student.setSex("女"); student.setAge("18"); Student student1 = new Student(); student1.setName("王美美"); student1.setSex("男"); student1.setAge("57"); List<Student> studentList = new ArrayList<>(); studentList.add(student); studentList.add(student1); studentList.stream().forEach(stu->{ System.out.println(stu.getName()); }); } 打印结果: 张三 王美美