本文介绍了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.
AbstractList 文档很好的详细描述.
这篇关于Java Modcount (ArrayList)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!