# 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](https://lxs-shmily.gitbook.io/java-notes/java-ji-chu/hashmap)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lxs-shmily.gitbook.io/java-notes/citicbank/citic-summary/10.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
