这样写代码时,遇到了上面的异常
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不匹配,此时无心深究