iterator

1、使用集合容器的iterator,该集合要继承Iterable接口

2、在集合的foreach里不要对集合进行remove和add。因为进行reove和add操作都会修改modCount值。

3、foreach是依据集合的内部iterator类实现的循环。而在这个内部类的循环里会检查modCount的值和expectedModCount的值是否相当,用来防止多线程操作时发生问题。其实应该避免这种操作。所以foreach时如果对list进行删除和添加时就会发生异常了。

猜你喜欢

转载自blog.csdn.net/wgp15732622312/article/details/79521743