如何在下面的代码中比较HashMap中的元素,删除键值对?我在使用HashMap时抛出java.util.ConcurrentModificationException
Map<BigDecimal, TransactionLogDTO> transactionLogMap = new HashMap<BigDecimal, TransactionLogDTO>();
for (BigDecimal regionID : regionIdList) {// Generation new logDTO
// objects for each in scope
// region
transactionLogMap.put(regionID, new TransactionLogDTO());
}
Set<BigDecimal> inScopeActiveRegionIdSet = new HashSet<BigDecimal>();
for (PersonDTO personDTO4 : activePersons) {
inScopeActiveRegionIdSet.add(personDTO4.getRegion());
}
for (BigDecimal bigDecimal : transactionLogMap.keySet()) {
if (!inScopeActiveRegionIdSet.contains(bigDecimal)) {
transactionLogMap.remove(bigDecimal);
}
}