Removing items from a collection in java while iterating over it

后端 未结 10 1765

I want to be able to remove multiple elements from a set while I am iterating over it. Initially I hoped that iterators were smart enough for the naive solution below to wor

10条回答
  •  时光取名叫无心
    2020-11-28 09:15

    Why don't you use the iterator's remove method on the objects you want to remove?

    Iterators were introduced mainly because enumerators couldn't handle deleting while enumerating.

提交回复
热议问题