Question - Is it safe to remove(...) entries while iterating over an OakMap
See original GitHub issueJava’s collections all don’t allow modifying one while iterating it, resulting in a ConcurrentModificationException
. If I want to remove some entries from an OakMap
while iterating through them, what is the proper way of achieving it?
For instance, I created a head map, tried to call clear()
on it, and failed with UnsupportedOperationException
. Iterator.remove
is not implemented for those returned from an OakMap
. And glancing the source code, I’m not quite sure if I can safely invoke remove
on an OakMap
, while iterating over its content.
Currently I’m iterating over the entries and calling remove
immediately after I’m done with each entry. Is it ok to do so?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Is it safe to delete HashMap's entry when iterating over its ...
I have found a related question (iterating over and removing from a map), but it assumes we are iterating over the key set....
Read more >Remove an Entry using key from HashMap while Iterating over it
Iterate over the HashMap using the Iterator.hasNext() method. While iterating, check for the key at that iteration to be equal to the key...
Read more >How to Remove Entry (key/value) from HashMap in Java while ...
Can you remove a key while iterating over HashMap in Java? This is one of the interesting interview questions as well as a...
Read more >for...of - JavaScript | MDN - MDN Web Docs
Each iteration executes statements that may refer to the current sequence value. When a for...of loop iterates over an iterable, it first calls ......
Read more >Javarevisited: How to delete a key value pair from a HashMap ...
Yes, we'll iterate over Map to check each value but we'll not use the two remove() methods from ... How to delete an...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@dynaxis , sounds great!
If you can explain a bit more your use-case, it will help us to understand our users more. Not urgent, when you have time. And if you want to know more about Oak internals, let me know. Thanks!
@dynaxis thank you so much for this detailed explanation!