//迭代器:集合特有的遍历方式Iterator<Student> iter = list.iterator();while(iter.hasNext()){Student s= iter.next();System.out.println(s.getName()+" "+s.getAge());}
//普通for:带有索引的遍历for(int i =0; i < list.size(); i++){Student s = list.get(i);System.out.println(s.getName()+" "+s.getAge());}//增强for循环遍历(最方便)for(Student s: list){System.out.println(s.getName()+" "+s.getAge());}
文章目录List集合储存学生对象的三种方式一、创建学生类二、创建List集合对象1.给集合添加元素List集合储存学生对象的三种方式一、创建学生类public class Student { private String name; private int age; public Student() { } public Student(String name, int age) { this.name = name; .