标签:iterator sys bsp class str linked void link add
public class TestList { public static void main(String[] args) { List<Integer> list = new LinkedList<Integer>(); list.add(2); list.add(3); for (Iterator iterator = list.iterator(); iterator.hasNext();) { System.out.println(list); Integer integer = (Integer) iterator.next(); iterator.remove(); } System.out.println(list); } }
[2, 3]
[3]
[]
错误的写法
for (Integer integer : list) { System.out.println(list); list.remove(integer); }
System.out.println(list);
[2, 3]
[3]
标签:iterator sys bsp class str linked void link add
原文地址:http://www.cnblogs.com/tonggc1668/p/7644381.html