Skip to content

Commit adc99f0

Browse files
committed
💬 update LinkedHashMap
1 parent e0a49ad commit adc99f0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

MD/collection/LinkedHashMap.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,19 @@ LinkedHashMap 的 `get()` 方法也重写了:
244244
}
245245
```
246246

247+
`clear()` 清空就要比较简单了:
248+
249+
```java
250+
//只需要把指针都指向自己即可,原本那些 Entry 没有引用之后就会被 JVM 自动回收。
251+
public void clear() {
252+
super.clear();
253+
header.before = header.after = header;
254+
}
255+
```
256+
257+
258+
## 总结
259+
260+
总的来说 `LinkedHashMap` 其实就是对 `HashMap` 进行了拓展,使用了双向链表来保证了顺序性。
261+
247262

0 commit comments

Comments
 (0)