From 7efbe3a4683d753f6c2957a2653f69dd4201ef65 Mon Sep 17 00:00:00 2001 From: jun <2395306536@qq.com> Date: Wed, 2 Aug 2023 10:39:56 +0800 Subject: [PATCH] update linkedhashmap-source-code.md --- docs/java/collection/linkedhashmap-source-code.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/java/collection/linkedhashmap-source-code.md b/docs/java/collection/linkedhashmap-source-code.md index 3ea1f36a..d74a62cb 100644 --- a/docs/java/collection/linkedhashmap-source-code.md +++ b/docs/java/collection/linkedhashmap-source-code.md @@ -118,6 +118,7 @@ LRUCache < Integer, String > cache = new LRUCache < > (2); cache.put(1, "one"); cache.put(2, "two"); cache.put(3, "three"); +cache.put(4, "four"); for (int i = 0; i < 4; i++) { System.out.println(cache.get(i)); } @@ -129,6 +130,7 @@ for (int i = 0; i < 4; i++) { null null three +four ``` 从输出结果来看,由于缓存容量为 2 ,因此,添加第 3 个元素时,第 1 个元素会被删除。添加第 4 个元素时,第 2 个元素会被删除。