在Iterator的内部有个expectedModCount 变量,
该变量每次初始化Iterator的时候等于ArrayList的modCount,modCount记录了对ArrayList的结构修改次数,
在通过Iterator对ArrayList进行结构的修改的时候都会将expectedModCount 与modCount同步,
但是如果在通过Iterator访问的时候同时又通过索引的方式去修改ArrayList的结构的话,
由于通过索引的方式只会修改modCount不会同步修改expectedModCount 就会导致
modCount和expectedModCount 不相等就会抛ConcurrentModificationException,
这也就是Iterator的fail-fast,快速失效的。所以只要采取一种方式操作ArrayList就不会出问题,
当然ArrayList不是线程安全的,此处不讨论对线程问题。