<分区>
当我尝试从 arraylist 中删除一个 int 时,我遇到了大约 20 个错误。这是一个强力球游戏,我试图删除匹配的球以避免重复的球
for (Integer ballNumber : balls) {
for (Integer yballNumber : yballs) {
if (ballNumber == yballNumber) {
match++;
balls.remove(ballNumber);
yballs.remove(yballNumber);
}
}
}
Exception in thread "main" java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
at java.util.ArrayList$Itr.next(ArrayList.java:851)
at PowerBall_Simulator.main(PowerBall_Simulator.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)