标签:contains pre util div cep odi lis bsp ati
这样写代码时,遇到了上面的异常
for(Question q:questionList) { if(!qIds.contains(q.getQuestionId())){ questionList.remove(q); } }
换成下面这种写法就正常了
for(int k=0;k<questionList.size();k++) { if(!qIds.contains(questionList.get(k).getQuestionId())){ questionList.remove(k); k--; } }
或
for(int k=0;k<questionList.size();k++) { if(!qIds.contains(questionList.get(k).getQuestionId())){ questionList.remove(questionList.get(k)); k--; } }
至于原因,有的博客提到的modCount与size不匹配,此时无心深究
list删除时java.util.ConcurrentModificationException
标签:contains pre util div cep odi lis bsp ati
原文地址:https://www.cnblogs.com/yanan7890/p/13053952.html