fork download
  1.  
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Iterator;
  5. import java.util.List;
  6.  
  7. class Test
  8. {
  9. public static void main(String args[])
  10. {
  11. List<String> myList = new ArrayList<String>();
  12.  
  13. for(int i=0; i<10; i++)
  14. {
  15. myList.add("String"+i);
  16. }
  17.  
  18.  
  19. int count = 0;
  20.  
  21. Iterator iter = myList.iterator();
  22. while(iter.hasNext())
  23. {
  24. count++;
  25. if(count % 2 == 0)
  26. myList.remove(count);
  27.  
  28. System.out.print(iter.next()+" ");
  29. }
  30. }
  31.  
  32. }
Runtime error #stdin #stdout #stderr 0.05s 4386816KB
stdin
Standard input is empty
stdout
String0  
stderr
Exception in thread "main" java.util.ConcurrentModificationException
	at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
	at java.util.ArrayList$Itr.next(ArrayList.java:851)
	at Test.main(Main.java:28)