Java - Exception in thread quot;mainquot; java.util.ConcurrentModificationException(Java - 线程“main中的异常java.util.ConcurrentModificationException)
问题描述
有什么方法可以在迭代时修改特定键的 HashMap
值?
下面给出一个示例程序:
抛出错误:
检测到对象的并发修改但不允许修改的方法可能会抛出此异常.
以下代码导致问题.
您正在迭代和修改相同的内容.通过创建 new ArrayList
阅读这里p>
Is there any way I can modify the HashMap
values of a particular key while iterating over it?
A sample program is given below:
Error Thrown:
This exception may be thrown by methods that have detected concurrent modification of an object when such modification is not permissible.
Below peice of code is causing the problem.
You are iterating and modifying the same. Avoid this by creating new ArrayList
have a read here
这篇关于Java - 线程“main"中的异常java.util.ConcurrentModificationException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!