java - What basic operations on a Map are permitted while iterating over it? -


Say I'm running on a map in Java again ... What do I do about the map during this process I can walk on this again and think that I am mostly confused by this warning in Javadok for the way to remove the Iter interface:

[...] The behavior of the Iterator Not specified if the underlying collection is modified during recurrence This method is in progress in any other way than to call.

I know that I can request the removal method without any issue. But while moving on the map archive, can I:

  1. Change the value associated with the key with the map class method (put with an existing key)?

  2. Add a new entry with map class push method (insert with a new key)?

  3. Remove an entry with the mapped class remove method?

My guess is that I can probably do # 1 (put on an existing key), but do not safely # 2 or # 3.

Thanks in advance for any explanation on this.

You can use Iterator.remove () , and if You are using the entry atter (map.Interrice) you can use the Map.Entry.setValue () . Some other and all bets are closed - You should not change the map directly, and some maps will not allow the aforementioned methods or both.

Specifically, your (1), (2) and (3) no are allowed.

You can get away from setting the value of an existing key through the Maybe map object, but is set. () Documentation specifically prevents it and this specificity will apply:

If the map is modified, then a repetition on the set is in progress, the removal of the itator's own Operation, or on the map entry returned by the itater through the set valley operation) Walking results are undefined (emphasis added)


Comments