Simple question: delete element from collection on condition?# Java - 爪哇娇娃
g*y
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.
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.