ArrayList迭代,删除list中内容出现ConcurrentModificationException
2012-09-04 11:20
447 查看
http://lggege.iteye.com/blog/249430
ArrayList 迭代删除问题,搞不好就出并发错误,底层代码没研究,暂先使用。
删除是使用Iterator或者用for在外边取出size挨个检索。
直接使用for(obj:list)出现问题
System.out.println("-2-使用Iterator的remove");
list = test.buildList();
try {
Iterator<String> iterator = list.iterator();
while (iterator.hasNext()) {
iterator.remove();
}
} catch (Exception e) {
// java.lang.IllegalStateException
e.printStackTrace();
}
ArrayList 迭代删除问题,搞不好就出并发错误,底层代码没研究,暂先使用。
删除是使用Iterator或者用for在外边取出size挨个检索。
直接使用for(obj:list)出现问题
System.out.println("-2-使用Iterator的remove");
list = test.buildList();
try {
Iterator<String> iterator = list.iterator();
while (iterator.hasNext()) {
iterator.remove();
}
} catch (Exception e) {
// java.lang.IllegalStateException
e.printStackTrace();
}
相关文章推荐
- 【Java基础】List迭代并修改时出现的ConcurrentModificationException问题
- 关于出现List的java.util.ConcurrentModificationException异常问题的解决
- ArrayList 使用迭代抛出ConcurrentModificationException解决方法
- 遍历并批量删除容器中元素出现ConcurrentModificationException原因及处置
- Java ConcurrentModificationException when clearing List and ArrayList
- java.util.ConcurrentModificationException---用迭代器遍历Map时删除其中元素出现异
- ArrayList删除倒数第二个元素不报ConcurrentModificationException原因-----阿里开发手册
- 关于迭代集合同时删除元素报错的问题java.util.ConcurrentModificationException
- java使用Iterator迭代出现"java.uitl.ConcurrentModificationException"错误原因及解决方法概述
- ArrayList迭代修改抛出ConcurrentModificationException
- 从ArrayList中删除对象报java.util.ConcurrentModificationException异常解决
- JAVA List 一边遍历一边删除元素,报java.util.ConcurrentModificationException异常
- 循环List删除元素抛ConcurrentModificationException异常原因分析
- 从ArrayList中删除对象报java.util.ConcurrentModificationException异常解决
- java 多线程同时操作ArrayList 出现ConcurrentModificationException 解决办法
- List删除元素报Exception in thread "main" java.util.ConcurrentModificationException异常,或数据删除不完整
- List ConcurrentModificationException出现原因以及避免方法
- 从ArrayList中删除对象报java.util.ConcurrentModificationException异常解决
- 再次踩bug:遍历删除list(java.util.ConcurrentModificationException)
- Java List删除指定的对像错误 ConcurrentModificationException