首页 > 其他 > 详细

For循环List中删除正确的方式

时间:2016-07-05 20:32:15      阅读:315      评论:0      收藏:0      [点我收藏+]
单线程
public
class Test { public static void main(String[] args) { ArrayList<Integer> list = new ArrayList<Integer>(); list.add(2); Iterator<Integer> iterator = list.iterator(); while(iterator.hasNext()){ Integer integer = iterator.next(); if(integer==2) iterator.remove(); //注意这个地方 } } }

  多线程

使用 使用并发容器CopyOnWriteArrayList

 

For循环List中删除正确的方式

原文:http://www.cnblogs.com/hansongjiang/p/5644723.html

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