//使用Stream流遍历一个集合
@Test
public void streamDemo01(){
List<Teacher> teacherList = new ArrayList<>();
teacherList.add(new Teacher(1L, "张三", 20));
teacherList.add(new Teacher(2L, "张三", 23));
teacherList.add(new Teacher(3L, "李四", 21));
teacherList.add(new Teacher(4L, "王五", 21));
teacherList.add(new Teacher(5L, "赵六", 24));
teacherList.stream().forEach(System.out::println);
/**结果:
Teacher(id=1, name=张三, age=20)
Teacher(id=2, name=张三, age=23)
Teacher(id=3, name=李四, age=21)
Teacher(id=4, name=王五, age=21)
Teacher(id=5, name=赵六, age=24)
*/
}
Stream流遍历
最新推荐文章于 2024-05-28 17:26:38 发布