![]() When an Iterator is initialized, the expectedModCount will be set to modCount. ![]() modCount is used to track the number of times this HashMap has been structurally modified. Structural modifications are those that change the number of mappings in the HashMap or otherwise modify its internal structure (e.g., rehash). The key here is the modCount and expectedModCount. ![]() To understand why this would happen, let's analyze the source code of HashMap. (iter.next()) //Will throw ConcurrentModificationException Map map = Collections.synchronizedMap(new TreeMap()) This issue would also occur to other Collection types such as Set, List.īelow is a sample code snippet demonstrating the exception thrown. This post will explain why exception would be thrown when deleting element with Map.remove() while looping through a Map using Iterator. HashMap and other Collection types are frequently used in Java application programming. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |