HashMap
Collection,collections
HashMap,HashTable,Map
fail-fast机制在遍历一个集合时,当集合结构被修改,会抛出Concurrent Modification Exception。
fail-fast会在以下两种情况下抛出ConcurrentModificationException
(1)单线程环境
集合被创建后,在遍历它的过程中修改了结构。
注意 Iteratore 的remove()方法会让expectModcount和modcount 相等,所以是不会抛出这个异常。
(2)多线程环境
当一个线程在遍历这个集合,而另一个线程对这个集合的结构进行了修改get方法
put方法
遍历方式
h & (length-1) 与操作 不用求 % 自 定义 2 的 n 的方数
Last updated
Was this helpful?