异常:Exception in thread "main" java.util.ConcurrentModificationException
2017-10-19 16:57
609 查看
错误代码:
Map<Integer,Integer> map = new HashMap<>(); map.put(1,1); map.put(2,2); map.put(3,3); map.put(4,4); for (Map.Entry<Integer,Integer> entry : map.entrySet()) { int key = entry.getKey(); int value = entry.getValue(); map.remove(key); }
原因:不能在迭代器中删除集合元素。具体原理等我后面再慢慢解释。先留一道题。
相关文章推荐
- 遍历集合时出现的异常Exception in thread "main" java.util.ConcurrentModificationException
- 遍历集合时出现的异常Exception in thread "main" java.util.ConcurrentModificationException
- List删除元素报Exception in thread "main" java.util.ConcurrentModificationException异常,或数据删除不完整
- 多线程报错 : Exception in thread "Thread-3" java.util.ConcurrentModificationException 并发修改异常
- Exception in thread "main" java.util.ConcurrentModificationException
- Exception in thread "main" java.util.ConcurrentModificationException
- Exception in thread "main" java.util.ConcurrentModificationException
- Exception in thread "main" java.util.ConcurrentModificationException
- java -- Exception in thread "main" java.util.ConcurrentModificationException
- Exception in thread "main" java.util.ConcurrentModificationExceptions
- Exception in thread "Thread-6" java.util.ConcurrentModificationException
- unit测试出现异常:Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util
- [置顶] Junit测试出现异常:Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util.
- Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException
- 发送邮件时遇到mail包冲突异常Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStream 解决方法
- Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException
- Junit测试出现异常:Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util.
- 异常:Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStream
- Exception in thread "main" java.util.NoSuchElementException
- java 集合排序异常Exception in thread "main" java.lang.IllegalArgumentException: Comparison method violate