public static void main(String[] args) {
Stu b1=new Stu(1,"张三",18,"男");
Stu b2=new Stu(9,"神侣",33,"女");
Stu b3=new Stu(4,"大神",111,"男");
Stu b4=new Stu(4,"大神",111,"男");
ArrayList<Stu> a = new ArrayList<Stu>();
a.add(b1);
a.add(b2);
a.add(b3);
a.add(b4);
a.add(null);
a.add(null);
Iterator<Stu> it = a.iterator();
while(it.hasNext()) {
System.out.println(it.next());
}
System.out.println("------------");
List<Stu>a1 = new LinkedList<Stu>();
a1.add(b1);
a1.add(b2);
a1.add(b3);
a1.add(b4);
a1.add(null);
a1.add(null);
Iterator<Stu> it1 = a1.iterator();
while(it1.hasNext()) {
System.out.println(it1.next());
}
result:
Stu [id=1, name=Zhang San, age=18, sex=male]
Stu [id=9, name=Shenlu, age=33, sex=female]
Stu [id=4, name=Great God, age= 111, sex=male]
Stu [id=4, name=Great God, age=111, sex=male]
null
null
------------
Stu [id=1, name=Zhang San, age =18, sex=male]
Stu [id=9, name=Shenlu, age=33, sex=female]
Stu [id=4, name=Great God, age=111, sex=male]
Stu [id=4, name=Great God, age=111, sex=male]
null
null