import java.util.ArrayList;
import java.util.Iterator;
public class IteratorQuestion {
public static void main(String[] args) {
ArrayList a1 = new ArrayList();
a1.add("java01");
a1.add("java02");
a1.add("java03");
for(Iterator it = a1.iterator();it.hasNext();) {
//System.out.println(it.next());
Object obj = it.next();
if(obj.equals("java02")) {
//a1.add("java99");//ConcurrentModificationException
a1.remove("java03");
}
}
for(Iterator it = a1.iterator();it.hasNext();){
System.out.println(it.next());
}
}
} |