GnuDeveloper.com

How to avoid the Concurrent exception

The cause of the exception is modifying the list after iterator is created, Hence we should do operation in list before the iterator is created means calling remove before iterator call .

List<Integer>  tmp = new ArrayList<Integer>(0); 
		tmp.add(1);
		tmp.add(2);
		Iterator<Integer> it =  tmp.iterator();
		tmp.remove(0); 
		System.out.println(" Exception will be fired here " + it.next());    

Groups: