我在以下代码中得到 ConcurrentModificationException
当我运行代码时它运行良好但突然抛出异常,我猜是由于列表的修改,但我不知道如何修复它
if (myRulesIncr!=null)
{
Iterator itReceivedRules = myRulesIncr.iterator();
while (itReceivedRules.hasNext())
{
RuleModel currentReceived = (RuleModel) itReceivedRules.next();
if (receivedRulesExisting!=null)
{
Iterator itReceivedRulesExisting = receivedRulesExisting.iterator();
while (itReceivedRulesExisting.hasNext())
{
RuleModel currentExisting = (RuleModel) itReceivedRulesExisting.next();
if(currentExisting.getRuleId().equals(currentReceived.getRuleId()))
{
//TODO:replace the rule else add it.
if(currentReceived.getStatus()!="D")
{
//replace the existing rule with the new one
receivedRulesExisting.remove(currentExisting);
receivedRulesExisting.add(currentReceived);
}
else
{
receivedRulesExisting.remove(currentExisting);
}
}
else
{
//Add the new rule to the existing rules
receivedRulesExisting.add(currentReceived);
}
}
}
}
}
请帮我解决这个问题。