PDF
1HashMapContents ............................................................................................... 1 ....................................................................................... 3fail-fast .......................................................................................... 4 ............................................................................................... 4使使static final int hash(Object key) { int h; // 16index使length // return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);}"a".hashCode() = 97 = 00000000000000000000000001100001hash("a") = 00000000000000000000000001100001 ^ 00000000000000000000000000000000 = 00000000000000000000000001100001index = hash("a") & (4 - 1) = 00000000000000000000000001100001 & 00000000000000000000000000000011 = 00000000000000000000000000000001 2Load Factor()Threshod使使initialCapacityloadFactorinitial capacity便int index = (length - 1) & hash/*final Node<K,V> getNode(int hash, Object key) { Node<K,V>[] tab; Node<K,V> first, e; int n; K k; if ((tab = table) != null && (n = tab.length) > 0 && (first = tab[(n - 1) & hash]) != null) { ...*/ 3abs(hash) % SIZETREEIFY_THRESHOLD使 bucket | elements bucket | elements -------+--------- -------+--------- 0 | Z 0 | 1 | X 1 | Z -> X -> Y 2 | 2 | 3 | Y 3 | * 0: 0.60653066* 1: 0.30326533* 2: 0.07581633* 3: 0.01263606* 4: 0.00157952* 5: 0.00015795* 6: 0.00001316* 7: 0.00000094* 8: 0.00000006* more: less than 1 in ten millionTREEIFY_THRESHOLD = 8Treeify 4AaBB线fail-fastmodCountConcurrentModificationExceptionjava.util线java.util.concurrentgetput使

HTML view coming soon.

Download PDF for the full formatted version.