集合源码阅读——ArrayList

集合源码阅读——ArrayList,第1张

集合源码阅读——ArrayList

ArrayList

关键点:

>>扩容每次扩容1.5倍

>>modcount的作用

  >>ArrayList的父类AbstractList的成员变量

  >>ArrayList中的许多方法都会出现modcount++的 *** 作

>>ArrayList中的迭代器,返回一个Itr类型的对象

  >>modCount在 *** 作ArrayList的时候会自增, 用来记录 *** 作的次数。



  >>父类AbstractList中的expectedModCount在new出迭代器的时候被初始化为和modCount一样的值了,在迭代器中如果 *** 作了列表,则会改变modCount,如果modCount和expectedModCount的值不一样(其他线程 *** 作了列表,改变了modCount的值),则会在checkForComodification()方法中,抛出ConcurrentModificationException异常了。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/586221.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-12
下一篇 2022-04-12

发表评论

登录后才能评论

评论列表(0条)

保存