GeezerVison is showing github.com — Merge pull request #153 from Flyonsnow/master · bajie123/JavaGuide@3748061
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: Java相关/HashMap.md +3-3Lines changed: 3 additions & 3 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -90,13 +90,13 @@ public class HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Cloneabl |
90 | 90 | transient int modCount; |
91 | 91 | // 临界值 当实际大小(容量*填充因子)超过临界值时,会进行扩容 |
92 | 92 | int threshold; |
93 | | - // 填充因子 |
| 93 | + // 加载因子 |
94 | 94 | final float loadFactor; |
95 | 95 | } |
96 | 96 | ``` |
97 | 97 | - **loadFactor加载因子** |
98 | 98 |
|
99 | | - loadFactor加载因子是控制数组存放数据的疏密程度,loadFactor越趋近于1,那么 数组中存放的数据(entry)也就越多,也就越密,也就是会让链表的长度增加,load Factor越小,也就是趋近于0, |
| 99 | + loadFactor加载因子是控制数组存放数据的疏密程度,loadFactor越趋近于1,那么 数组中存放的数据(entry)也就越多,也就越密,也就是会让链表的长度增加,loadFactor越小,也就是趋近于0,数组中存放的数据(entry)也就越少,也就越稀疏。 |
100 | 100 |
|
101 | 101 | **loadFactor太大导致查找元素效率低,太小导致数组的利用率低,存放的数据会很分散。loadFactor的默认值为0.75f是官方给出的一个比较好的临界值**。 |
102 | 102 |
|
@@ -401,7 +401,7 @@ final Node<K,V>[] resize() { |
401 | 401 | else if (oldThr > 0) // initial capacity was placed in threshold |
402 | 402 | newCap = oldThr; |
403 | 403 | else { |
404 | | - signifies using defaults |
| 404 | + // signifies using defaults |
405 | 405 | newCap = DEFAULT_INITIAL_CAPACITY; |
406 | 406 | newThr = (int)(DEFAULT_LOAD_FACTOR * DEFAULT_INITIAL_CAPACITY); |
407 | 407 | } |
|