本帖最后由 张凯 于 2012-7-26 07:28 编辑
为什么- public static void main(String[] args) {
- List<integer> list=new ArrayList<integer>(Arrays.<integer>asList(1,2,3,5));
- for(Integer l:list){
- if(l==3){
- list.remove(l);
- }
- }
- System.out.println(list);
- }
复制代码 不抛异常,而- public static void main(String[] args) {
- List<integer> list=new ArrayList<integer>(Arrays.<integer>asList(1,2,3,5,6));
- for(Integer l:list){
- if(l==3){
- list.remove(l);
- }
- }
- System.out.println(list);
- }
复制代码 就抛Exception in thread "main" java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:449)
at java.util.AbstractList$Itr.next(AbstractList.java:420)
at Test3.main(Test3.java:11)
???实在想不明白 |