首页 > 编程语言 > 详细

Java笔记

时间:2015-03-23 00:07:10      阅读:237      评论:0      收藏:0      [点我收藏+]

1. ConcurrentModificationException 在遍历容器的同时修改容器里的成员对象可能会抛出该异常

    http://www.blogjava.net/EvanLiu/archive/2008/08/31/224453.html

  故在迭代的同时删除容器里的元素要用迭代器的iter.remove()方法,而不要使用容器自带的remove(obj)方法。例如:

Iterator<Element> e = list.iterator();    
     while(e.hasNext()){    
    Element element = e.next();  
    if(condition){  
        e.remove();  
    }  
}  
foreach(element e: list){  
    if(condition){  
        list.remove(e);  //throw ConcurrentModificationException
    }  
}; 

 

2. 

Java笔记

原文:http://www.cnblogs.com/xingyun/p/4358289.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!