类文档声明 Entry
不能通过 .setValue(...)
修改,但也警告 put(...)
工作正常。
这是否意味着 put(...)
在像 navigableKeySet()
这样的 Collection View 上迭代时会正常工作(即,不会导致 ConcurrentModificationException
),只要不进行结构修改(即添加新 key )?
我正在测试它,但如果我无法中断迭代,我仍然希望验证它是否正常工作(而不是我无法中断它)。
最佳答案
A structural modification is any operation that adds or deletes one or more mappings; merely changing the value associated with an existing key is not a structural modification.
因此,可以假设在迭代键集时更改与给定键关联的值是允许的。
关于java.util.TreeMap 行为问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3135246/