ConcurrentModificationException



http://stackoverflow.com/questions/1496180/concurrent-modification-exception


Between creating the iterator and starting to use the iterator, you added arguments to the list that is to be iterated. This is a concurrent modification.

    ListIterator<String> it = s.listIterator();  

    for (String a : args)
        s.add(a);                    // concurrent modification here

    if (it.hasNext())
        String item = it.next();     // exception thrown here

Create the iterator AFTER you've finished adding elements to the list:

    for (String a : args)
        s.add(a); 

    ListIterator<String> it = s.listIterator();  
    if (it.hasNext())
        String item = it.next();
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章