java.util.ConcurrentModificationException异常解决
2016-01-20 16:37
573 查看
当contents由contents = new ArrayList<>();或contents = Collections.synchronizedList(new ArrayList());这两种方式创建时,在contents.remove(str);时便会抛出如标题所示异常。解决方法如下:
List<String> contents = new CopyOnWriteArrayList<>(new ArrayList());//Collections.synchronizedList(new ArrayList<String>());//new ArrayList<>(); for (int i = 0 ; i < 100; i ++) { contents.add("list" + i); } for (String str: contents) { if (str.equals("list20")) { contents.remove(str); } }
相关文章推荐
- Ruby中的异常处理代码编写示例
- C#.Net ArrayList的使用方法
- VBS ArrayList Class vbs中的数组类
- MySQL抛出Incorrect string value异常分析
- C#中Arraylist的sort函数用法实例分析
- C#中ArrayList的使用方法
- C#中Array与ArrayList用法及转换的方法
- 详解JavaScript中的异常处理方法
- java程序中的延时加载异常及解决方案
- 解析Java异常的栈轨迹及其相关方法
- .NET(C#):Emit创建异常处理的方法
- windows7服务器上weblogic启动失败异常解决方法
- 有关ajax的error与后台的异常问题解决
- 深入探讨JAVA中的异常与错误处理
- GO语言异常处理机制panic和recover分析
- 浅谈JAVA 异常对于性能的影响
- C#生成随机ArrayList的方法
- 解析C++编程中的bad_cast异常
- C++ 异常处理 catch(...)介绍
- c# ArrayList的使用方法小总结