黑马程序员技术交流社区

标题: Exception in thread "main" java.util.ConcurrentModificationException [打印本页]

作者: Sparky    时间: 2015-7-20 22:45
标题: Exception in thread "main" java.util.ConcurrentModificationException
这个异常怎么解决啊
public class ListDemo {
public static void main(String[] args) {
        List l = new ArrayList();
        Student s1 = new Student("刘德华",20);
        Student s2 = new Student("赵本山",60);
        Student s3 = new Student("林青霞",26);
        l.add(s1);
        l.add(s2);
        l.add(s3);
        System.out.println(l);
        ListIterator it = l.listIterator();
        while(it.hasNext())
        {
                Student s = (Student)it.next();
                System.out.println(s.getName()+"--->"+s.getAge());
                Student s4 = new Student("刘欢",60);
                l.add(s4);
        }
        System.out.println(l.get(0).toString());
}
}




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2