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()); }
结果:
Stu [id=1, name=张三, age=18, sex=男]
Stu [id=9, name=神侣, age=33, sex=女]Stu [id=4, name=大神, age=111, sex=男]Stu [id=4, name=大神, age=111, sex=男]nullnull------------Stu [id=1, name=张三, age=18, sex=男]Stu [id=9, name=神侣, age=33, sex=女]Stu [id=4, name=大神, age=111, sex=男]Stu [id=4, name=大神, age=111, sex=男]nullnull