Iterator it = al.iterator();
while(it.hasNext()){
System.out.println(it.next());
}
it指向了一个对象,循环结束后it还在内存中,
而for循环
for(Iterator it = al.iterator();it.hasNext()){
System.out.println(it.next());
}
it是个局部变量,for循环结束后,it就释放了
-----------------------------------------------------------------------------------
那我把上面的代码修改一下呢! 如下
Iterator it = al.iterator();
while(it.hasNext()){
System.out.println(it.next());
}
it指向了一个对象,循环结束后it还在内存中,
而for循环
Iterator it;
for( it = al.iterator();it.hasNext()){
System.out.println(it.next());
}
哈哈还怎么说呢?
it是个局部变量,for循环结束后,it就释放了 |