val iterator = map.entries.iterator()
while (iterator.hasNext()) {
iterator.next()
iterator.remove()
}
I think concurrent hash maps support removal via the iterator, though not all collections do
👍 1
c
Chris Lee
11/03/2022, 1:55 PM
yea. the specifics will depend on the atomicity needed - should the whole operation (iteration + removals) be atomic, or can some level of staleness be tolerated?
e
ephemient
11/08/2022, 12:33 PM
you can usually use retainAll/removeAll (with a predicate) instead of working with the iterator directly