标签:exce equals 移动 ott highlight span rem exception 删除
印象中循环删除list中的元素使用for循环的方式是有问题的,但是可以使用增强的for循环,然后今天在使用时发现报错了,然后去科普了一下,再然后发现这是一个误区。
for(int i=0;i<list.size();i++){
     if(list.get(i).equals("del"))
     list.remove(i);
}
for(String x:list){
if(x.equals("del"))
list.remove(x);
}
Iterator<String> it = list.iterator();
while(it.hasNext()){
String x = it.next();
if(x.equals("del")){
it.remove();
}
}
标签:exce equals 移动 ott highlight span rem exception 删除
原文地址:https://www.cnblogs.com/ykpkris/p/13328470.html