我有这个哈希图
HashMap <Integer,Integer> H = new HashMap <Integer,Integer>();
Run Code Online (Sandbox Code Playgroud)
当我尝试从 HashMap 中删除密钥时,我收到此错误
**Exception in thread "main" java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextEntry(HashMap.java:922)
at java.util.HashMap$KeyIterator.next(HashMap.java:956)
at Livre.montantTotal(Livre.java:42)**
Run Code Online (Sandbox Code Playgroud)
这是我的代码
for (int e : H.keySet()){
H.put(e, H.get(e)-1);
if (H.get(e) == 0){
H.remove(e);
}
}
Run Code Online (Sandbox Code Playgroud)