麻烦迭代列表并删除项目 [英] Trouble iteration over a list and removing items

查看:73
本文介绍了麻烦迭代列表并删除项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我编写了以下方法。

它应该删除LinkedList中的对象。

这些对象隐含与其他对象的连接。

如果删除了一个对象,其他对象中的所有连接也应该被删除。


所有这些代码应该做我想要的。唯一的问题是我得到一个运行它的 ConcurrentModificationException

API中的
它表示

Hi guys,

ive written the following method.
its supposed to delete objects in a LinkedList.
These objects implicit Connections to other objects.
if one object is deleted all the connections in the other objects should be deleted as well.

all in all this code should do what I want. the only problem is that i get an ConcurrentModificationException running it.

in the API it says


当不允许进行此类修改时,检测到并发修改对象的方法可能抛出此异常。
This exception may be thrown by methods that have detected concurrent modification of an object when such modification is not permissible.



遗憾的是我无法弄清楚问题

如果有人能提供帮助,
会很棒。!


非常感谢

unfortunately I cant figure out the problem

would be great if anybody can help.!

Thanks very much

展开 | 选择 | Wrap | 行号

推荐答案

首先,仅供参考好玩,可以更简洁地写成:

First, just for fun, that could have been written more succinctly as:

展开 | 选择 | Wrap | 行号


循环本身

第5行:)


感谢提示
the loop itself
line 5 :)

thanks for the tip



循环本身

第5行:)


感谢提示
the loop itself
line 5 :)

thanks for the tip



我没有把所有代码都放在我面前。 deleteConnection是否也从列表中删除了连接?

I don''t have all your code in front of me. Does deleteConnection remove the Connection from the list, too?


这篇关于麻烦迭代列表并删除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆