import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
/*
* 用集合存储自定义对象,并输出每个对象元素属性.
*/
public class IteratorTest {
public static void main(String[] args) {
ArrayList<Student> c = new ArrayList<Student>();
Student s1 = new Student();
s1.setName("欧阳锋");
s1.setAge(88);
Student s2 = new Student();
s2.setName("郭靖");
s2.setAge(66);
Student s3 = new Student();
s3.setName("杨过");
s3.setAge(48);
c.add(s1);
c.add(s2);
c.add(s3);
//System.out.println(c);
Iterator<Student> it = c.iterator();
while(it.hasNext()){
Student s = (Student)it.next();
System.out.println(s.getName()+"***"+s.getAge()); // System.out.println(((Student)it.next()).getName()+"***"+((Student)it.next()).getAge());这个为什么会出错呢?编译正常,运行报错,java.util.NoSuchElementException,怎么就访问越界呢?和上面的一样的实现,上面那个就正确....求帮助。