先看代码
class Solution {
public static void main(String[] args) {
List<Integer> a=new LinkedList<>();
for (int i=0;i<11;i++){
a.add(i);
}
System.out.println(a);
for (Integer b:a){
if (b.equals(new Integer(3))) a.remove(new Integer(3));
}
System.out.println(a);
}
}
class Solution {
public static void main(String[] args) {
List<Integer> a=new LinkedList<>();
for (int i=0;i<11;i++){
a.add(i);
}
System.out.println(a);
Iterator<Integer> it= a.iterator();
while (it.hasNext()){
if (it.next().equals(new Integer(3))) a.remove(new Integer(3));
}
System.out.println(a);
}
}
执行结果同为下图。