HTML & JS
// Java program to demonstrate working of
// Iterator.remove() on an integer arraylist
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;

public class GFG
{
    public static void main(String[] args)
    {
        List al = new ArrayList();
        al.add(1);
        al.add(2);        
        al.add(10);
        al.add(20);
        al.add(30);

        // Remove elements smaller than 10 using
        // Iterator.remove()
        Iterator itr = al.iterator();
        while (itr.hasNext())
        {
            int x = (Integer)itr.next();
            if (x >= 10)
                al.remove(new Integer(x));
        }

        System.out.println("Modified ArrayList : "
                                           + al);
    }
}

Generated URL:

Warnings:

 GFG.java uses unchecked or unsafe operations.
 Recompile with -Xlint:unchecked for details.

Runtime Errors:

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 GFG.main(GFG.java:23)

Output:

No Output
Report Bug