Skip to content

Commit

Permalink
Merge pull request #2351 from TymGitHub/main
Browse files Browse the repository at this point in the history
LinkedHashMap勘误
  • Loading branch information
Snailclimb committed Apr 1, 2024
2 parents 128ed38 + 1aa8884 commit ca6da95
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions docs/java/collection/linkedhashmap-source-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ cache.put(1, "one");
cache.put(2, "two");
cache.put(3, "three");
cache.put(4, "four");
for (int i = 0; i <= 4; i++) {
cache.put(5, "five");
for (int i = 1; i <= 5; i++) {
System.out.println(cache.get(i));
}
```
Expand All @@ -128,12 +129,13 @@ for (int i = 0; i <= 4; i++) {

```java
null
two
null
three
four
five
```

从输出结果来看,由于缓存容量为 2 ,因此,添加第 3 个元素时,第 1 个元素会被删除。添加第 4 个元素时,第 2 个元素会被删除。
从输出结果来看,由于缓存容量为 3 ,因此,添加第 4 个元素时,第 1 个元素会被删除。添加第 5 个元素时,第 2 个元素会被删除。

## LinkedHashMap 源码解析

Expand Down

0 comments on commit ca6da95

Please sign in to comment.