import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class List_Test {
public static void main(String[] args) {
List list = new ArrayList();
list.add("Java");
list.add("JavaWeb");
list.add("JavaEE");
System.out.println(list);
method(list);
}
private static void method(List list) {
for (Iterator it = list.iterator(); it.hasNext(); ) {
String s = (String)it.next();
//判断当前元素是否为Java
if ("Java".equals(s)) {
//向集合中添加一个新的元素为"Android"
list.add("Android");
} //为什么报这样的错误 : Exception in thread "main" java.util.ConcurrentModificationException
}
}
}
|