Я получаю ConcurrentModificationException в следующем фрагменте кода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);
}
}
}
}
}
Пожалуйста, помогите мне в этом.
Какую коллекцию вы используете? – subodh
Пожалуйста, конвертируйте вкладки в пробелы в свой код, прежде чем вставлять их в редактор здесь. В противном случае ваш код будет трудно читать, уменьшая ваши шансы получить полезную помощь. –