Redian新闻
>
需要一个动态的List,不要ConcurrentModificationException
avatar
需要一个动态的List,不要ConcurrentModificationException# Java - 爪哇娇娃
c*e
1
哔哔耶斯上依然这样累不累啊
ps 我管得着么我
avatar
b*i
2
就是要构造一个容器,初始化只加入一个对象。
然后我就开始遍历这个容器,当作Breadth First Search那种,就当前指向的对象,我
要在容器中加入新的对象,我不会重复加入同样的对象,然后我继续遍历,直到我处理
最后一个对象时没有加入新对象为止。
我用LinkedList产生上述错误,请问有哪个List可以一边遍历一边动态加入对象?我是
单线程的。谢谢!
avatar
S*w
3
淡定

【在 c*****e 的大作中提到】
: 哔哔耶斯上依然这样累不累啊
: ps 我管得着么我

avatar
f*n
4
You don't need to iterate. To do BFS, you just need to add to one end and
remove from the other. To remove from the beginning of LinkedList you can
use .removeFirst().
avatar
z*g
5
一松懈就有人挑你毛病
兢兢业业, 诚惶诚恐说的就是实践经验总结啊。

【在 c*****e 的大作中提到】
: 哔哔耶斯上依然这样累不累啊
: ps 我管得着么我

avatar
b*i
6
我需要判断是否重复,是个图,所以把某个点附近的点都加入,为了防止兜圈子,我用
了两个LinkedList,一个每次删掉第一个,另一个不删除,只增加,这样可以避免
Exception,也可以避免重复。
就没有一个可以不出现这个Exception的,又 iterate?

【在 f*******n 的大作中提到】
: You don't need to iterate. To do BFS, you just need to add to one end and
: remove from the other. To remove from the beginning of LinkedList you can
: use .removeFirst().

avatar
c*e
7
其实我现在也属于不正常状态,所以看他们都觉得烦

【在 z********g 的大作中提到】
: 一松懈就有人挑你毛病
: 兢兢业业, 诚惶诚恐说的就是实践经验总结啊。

avatar
g*g
8
There's no difference between iterate and removeFirst. But if you insist,
try LinkedBlockingQueue, which has an weak consistent iterator that won't
throw this exception.

【在 b***i 的大作中提到】
: 我需要判断是否重复,是个图,所以把某个点附近的点都加入,为了防止兜圈子,我用
: 了两个LinkedList,一个每次删掉第一个,另一个不删除,只增加,这样可以避免
: Exception,也可以避免重复。
: 就没有一个可以不出现这个Exception的,又 iterate?

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。