Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 98c9396

Browse filesBrowse files
committed
Update HashMap(JDK1.8)源码+底层数据结构分析.md
1 parent 6093a1c commit 98c9396
Copy full SHA for 98c9396

File tree

Expand file treeCollapse file tree

1 file changed

+4
-7
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+4
-7
lines changed
Open diff view settings
Collapse file

‎docs/java/collection/HashMap(JDK1.8)源码+底层数据结构分析.md‎

Copy file name to clipboardExpand all lines: docs/java/collection/HashMap(JDK1.8)源码+底层数据结构分析.md
+4-7Lines changed: 4 additions & 7 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
<!-- @import "[TOC]" {cmd="toc" depthFrom=1 depthTo=6 orderedList=false} -->
32

43
<!-- code_chunk_output -->
@@ -21,14 +20,13 @@
2120
2221
## HashMap 简介
2322

24-
HashMap 主要用来存放键值对,它基于哈希表的 Map 接口实现,是常用的 Java 集合之一。
23+
HashMap 主要用来存放键值对,它基于哈希表的 Map 接口实现,是常用的 Java 集合之一,是非线程安全的
2524

26-
JDK1.8 之前 HashMap 由 数组+链表 组成的,数组是 HashMap 的主体,链表则是主要为了解决哈希冲突而存在的(“拉链法”解决冲突)。
25+
`HashMap` 可以存储 null 的 key 和 value,但 null 作为键只能有一个,null 作为值可以有多个
2726

28-
JDK1.8 之后 HashMap 的组成多了红黑树,在满足下面两个条件之后,会执行链表转红黑树操作,以此来加快搜索速度
27+
JDK1.8 之前 HashMap 由 数组+链表 组成的,数组是 HashMap 的主体,链表则是主要为了解决哈希冲突而存在的(“拉链法”解决冲突)。 JDK1.8 以后的 `HashMap` 在解决哈希冲突时有了较大的变化,当链表长度大于阈值(默认为 8)(将链表转换成红黑树前会判断,如果当前数组的长度小于 64,那么会选择先进行数组扩容,而不是转换为红黑树)时,将链表转化为红黑树,以减少搜索时间
2928

30-
- 链表长度大于或等于阈值(默认为 8)
31-
- HashMap 数组长度大于或等于 64
29+
`HashMap` 默认的初始化大小为 16。之后每次扩充,容量变为原来的 2 倍。并且, `HashMap` 总是使用 2 的幂作为哈希表的大小
3230

3331
## 底层数据结构分析
3432

@@ -574,5 +572,4 @@ public class HashMapDemo {
574572
}
575573

576574
}
577-
578575
```

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.