> For the complete documentation index, see [llms.txt](https://lxs-shmily.gitbook.io/java-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lxs-shmily.gitbook.io/java-notes/citicbank/citic-summary/10.md).

# HashMap和HashTable的区别.要深层理解,不只是线程安全,还有Hash算法的区别

## HashTable

![HashTabl](https://26655177-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LnRJnRZvnPN4YODatVc%2F-LnWHXx3OlRy2zUbt6Hm%2F-LnWHZRSKS98PGaxDh8g%2FHashTable.png?generation=1567147838573164\&alt=media)

## HashMap

![HashMap](https://26655177-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LnRJnRZvnPN4YODatVc%2F-LnWHXx3OlRy2zUbt6Hm%2F-LnWHZRUPFOZoO2V0IGg%2FHashMap.png?generation=1567147843180038\&alt=media)

```
HashTable直接使用的是hashcode值然后使用除留余数法求出下标位置，而HashMap是使用 Hash值后重新进行了与运算，而且HashTable的
扩容时是int newCapacity = (oldCapacity << 1) + 1;，容量变为原来的2n+1，
HashMap默认的初始化大小为16。之后每次扩充newThr = oldThr << 1;，容量变为原来的2倍。
```

详细参考[HashMap](/java-notes/java-ji-chu/hashmap.md)
