3颂龙、iterator遍歷
復(fù)制代碼
Iterator<String> it = list.iterator();
while(it.hasNext()){
? ? String x = it.next();
? ? if(x.equals("del")){
? ? ? ? it.remove();
? ? }
}
復(fù)制代碼
這種方式可以正常的循環(huán)及刪除刻诊。但要注意的是袍辞,使用iterator的remove方法渣叛,
總結(jié):
±伞(1)循環(huán)刪除list中特定一個元素的峦失,可以使用三種方式中的任意一種坯沪,但在使用中要注意上面分析的各個問題悴灵。
】秆俊(2)循環(huán)刪除list中多個元素的,應(yīng)該使用迭代器iterator方式积瞒。