Advertisement
Genesis2001

Concurrent Modification Demo

Dec 8th, 2012
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1. package org.unifiedtech.demo;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. public class Program
  6. {
  7.     public static void main(String[] args)
  8.     {
  9.         ArrayList<Integer> list = new ArrayList<Integer>();
  10.        
  11.         for(Integer i = 0; i < 100; i++)
  12.             list.add(i);
  13.        
  14.         for(int i : list)
  15.             if ((i % 2) == 0)
  16.                 list.remove(list.indexOf(i));
  17.     }
  18. }
  19.  
  20.  
  21. Exception in thread "main" java.util.ConcurrentModificationException
  22.     at java.util.AbstractList$Itr.checkForComodification(Unknown Source)
  23.     at java.util.AbstractList$Itr.next(Unknown Source)
  24.     at org.unifiedtech.demo.Program.main(Program.java:14)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement