Collection col = new ArrayList();
col.add(new Student("123",20));
col.add(new Student("acb",22));
col.add(new Student("!@#",19));
//1. 集合方法iterator()获取迭代器对象
Iterator it = col.iterator();
//2. 循环调用hasNext方法,判断集合中有没有下一个元素
while(it.hasNext()){
Student stu =(Student) it.next();
System.out.println(stu.getName()+".."+stu.getAge());
} |
|