I'm trying delete strings which have even index numbers in this ArrayList, using "Iterator".remove.
import java.util.*;
import static java.lang.System.out;
class MAIN
{
public static void main(String args[])
{
ArrayList<String> al = new ArrayList<String>();
Iterator i = al.iterator();
int len;
Scanner sc = new Scanner(System.in);
out.printf("Size:");
len = sc.nextInt();
while( len!=0 )
{
al.add( sc.next() );
len -= 1;
}
Object o;
for( len = 0 ; len < al.size() ; len +=1)
{
out.println(al);
if( len%2==0 )
{
o = i.next();
out.println(o);
i.remove();
i.next();
}
}
return;
}
}
I'm getting the "ConcurrentModificationException" at i.next();. What's wrong ?