package cn.itcast_01;
/*
*
*创建学生对象,把学生对象放在迭代器中,然后通过迭代器遍历
*不要多次使用it.next()方法
*
*/
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
public class IteratorTest {
public static void main(String[] args) {
//创建集合对象
Collection it=new ArrayList();
//创建学生对象
Student s1=new Student("射雕英雄",22);
Student s2=new Student("九阴真经",11);
Student s3=new Student("乾坤大挪移",22);
Student s4=new Student("盖世英雄",12);
//把学生对象添加到集合中
it.add(s1);
it.add(s2);
it.add(s3);
it.add(s4);
//迭代器遍历数组
Iterator cc=it.iterator();
while (cc.hasNext()) {
System.out.println(cc.next());
//可以通过下面的方式得到自己想要的文字
Student se=(Student)cc.next();
System.out.println(se.getName());
}
}
}