gpt4 book ai didi

java - 在使用它迭代java时从arraylist中删除项目

转载 作者:行者123 更新时间:2023-11-29 05:12:19 26 4
gpt4 key购买 nike

<分区>

当我尝试从 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)

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com