java.util.ConcurrentModificationException & iteration?

前端 未结 3 934
孤独总比滥情好
孤独总比滥情好 2021-01-25 22:28

I\'m so very new to Arraylists & iterators & this is the first time I got this exception. I have an ArrayList u & I\'d like to do the following algorithm:

         


        
3条回答
  •  广开言路
    2021-01-25 23:29

    how exactly i must put the while(iter.hasNext())

    You can use iterator as below:

    Iterator iter = u.iterator();
    while(iter.hasNext())
    {
      Character c = iter.next();
      .....
    }
    

    Initialize your list with generics: List u = new ArrayList();

    Hint: use iter.remove(), iter.add() wherever applicable instead of u.remove() and u.add().

    You need to start here: http://www.tutorialspoint.com/java/java_using_iterator.htm

提交回复
热议问题