public static voidmain(String[] args) {
List list =newArrayList<>();
list.add("A1");
list.add("A2");
System.out.println(list.get(0));
// Iterator iterator = list.iterator(); //正确用法
// while (iterator.hasNext()){
// System.out.println(iterator.next());
// }
while(list.iterator().hasNext()){ //错误用法,陷入死循环
System.out.println(list.iterator().next());
}
网友评论