由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - Simple question: delete element from collection on condition?
相关主题
web service returns HashMap that contains multiple ArrayListJava 面试常见问题!
问一道关于Vector的题几个Java面试题
HashMap 怎样循环用更快?请问这个面试题,关于synchronize hashmap
How to check if an element is in an array?improve speed
interview question问个ArrayList的问题
让大家了解工业界Java/J2EE面试题的难度如何遍历hashtable里边的每一项?
Why java.lang.Iterable depends on java.util.IteratorSplit a String into valid English words
Java里有没有象cell array一样的东西哪位大哥总结一下Iterator这些数据集合
相关话题的讨论汇总
话题: delete话题: collection话题: condition话题: loop话题: simple
进入Java版参与讨论
1 (共1页)
g**********y
发帖数: 14569
1
I find this annoyance in ArrayList/HashSet/HashMap...
If I want to loop through iterator and delete some elements on condition, I
have to do it:
1. Loop through iterator and find all elements satisfy condition, save them
in a collection.
2. Delete temp collection elements from original collection.
I have to do two steps because iterator can't be broken during loop. Is
there a better/simpler way to do this? I have no limitation on the data
structure.
Thanks.
g*****g
发帖数: 34805
2
This is probably the best practice anyway, you know
delete one item at a time from an Array can be N times
slower than what you are doing here.

I
them

【在 g**********y 的大作中提到】
: I find this annoyance in ArrayList/HashSet/HashMap...
: If I want to loop through iterator and delete some elements on condition, I
: have to do it:
: 1. Loop through iterator and find all elements satisfy condition, save them
: in a collection.
: 2. Delete temp collection elements from original collection.
: I have to do two steps because iterator can't be broken during loop. Is
: there a better/simpler way to do this? I have no limitation on the data
: structure.
: Thanks.

m******t
发帖数: 2416
3
You can certainly do iterator.remove() while in the loop. That's what
AbstractCollection.removeAll does anyway.

I
them

【在 g**********y 的大作中提到】
: I find this annoyance in ArrayList/HashSet/HashMap...
: If I want to loop through iterator and delete some elements on condition, I
: have to do it:
: 1. Loop through iterator and find all elements satisfy condition, save them
: in a collection.
: 2. Delete temp collection elements from original collection.
: I have to do two steps because iterator can't be broken during loop. Is
: there a better/simpler way to do this? I have no limitation on the data
: structure.
: Thanks.

1 (共1页)
进入Java版参与讨论
相关主题
哪位大哥总结一下Iterator这些数据集合interview question
ArrayList and Link list让大家了解工业界Java/J2EE面试题的难度
Collection return type and web serviceWhy java.lang.Iterable depends on java.util.Iterator
你们有人测试过这种语法么?Java里有没有象cell array一样的东西
web service returns HashMap that contains multiple ArrayListJava 面试常见问题!
问一道关于Vector的题几个Java面试题
HashMap 怎样循环用更快?请问这个面试题,关于synchronize hashmap
How to check if an element is in an array?improve speed
相关话题的讨论汇总
话题: delete话题: collection话题: condition话题: loop话题: simple