public void searchOwner(List<Appointments> appts, String owner) {
Appointments theOne = null;
for (Appointments temp : appts) {
if (owner.equalsIgnoreCase(temp.owner.name)) {
System.out.println(temp.data);
temp.setResolved(true);
}
}
}
public void checkRemoval() {
for (Appointments appts : appointments) {
if (appts.resolved == true) {
appointments.remove(appts);
}
//Iterator method used before enhanced for-loop
public void checkRemovalI(){
Iterator<Appointments> it = appointments.iterator();
while(it.hasNext()){
if(it.next().resolved = true){
it.remove();
}
}
}
到目前为止,这是我遇到我的问题的地方。我正在尝试检查约会的arrayList并查看该字段(已解决)是否设置为true,但在尝试将resolve =设置为true时,我在searchOwner方法期间收到ConcurrentModification异常。我已经尝试在checkRemoval中使用Iterator,而不是增强的for-loop,但是这也没有帮助。我真的只需要将约会设置为true的那部分工作,checkRemoval似乎在实现布尔解析更改之前提前工作。任何帮助将不胜感激,谢谢。从集合中删除项目/对象的更改字段
你可以使用迭代器发布代码 –
我认为你的问题不是使用resolve = true的设置,而是使用checkRemoval方法。循环播放时无法修改列表。要么将原始列表的副本放到其他列表中,并从那里开始工作 – vikeng21