I am getting ConcurrentModificationException
when iterating over a content of a map
for (String sourceKey : sMap.getContent().keySet()) {
List<String> sourceValues = sMap.getValues(sourceKey);
List<String> targetValues = tMap.getValues(sourceKey);
if (areMultiple(sourceValues)) {
....
}
sMap.getContent()
returns Map<String, List<String>>
, of which i am getting keys only.
Note that no modification of map's content is done. I am only iterating here.
What am i doing wrong here? How can i correct the situation when exception is thrown?
This will occur if the underlying collection that is being iterated over is modified by anything other than the Iterator itself.
Try using a ConcurrentHashMap instead of a plain HashMap
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.