Java Modcount(ArrayList) [英] Java Modcount (ArrayList)
问题描述
在Eclipse中,我看到 ArrayList
对象有一个modCount字段。它的目的是什么? (修改的数目?)
In Eclipse, I see that ArrayList
objects have a modCount field. What is its purpose? (number of modifications?)
推荐答案
它允许列表的内部结构知道是否有结构修改导致当前操作给出不正确的结果。
It allows the internals of the list to know if there has been a structural modification made that might cause the current operation to give incorrect results.
如果由于修改列表而导致 ConcurrentModificationException
例如,删除一个项目),同时迭代它,它的内部 modCount
是迭代器的顶部。
If you've ever gotten ConcurrentModificationException
due to modifying a list (say, removing an item) while iterating it, its internal modCount
was what tipped off the iterator.
a href =https://docs.oracle.com/javase/7/docs/api/java/util/AbstractList.html#modCount =nofollow noreferrer> AbstractList docs 提供了详细的说明。
The AbstractList docs give a good detailed description.
这篇关于Java Modcount(ArrayList)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!