From d7756c7af8ccddae5b2f3fd93ba545240b4c2433 Mon Sep 17 00:00:00 2001 From: JianXinyi <1259606552@qq.com> Date: Thu, 23 Apr 2026 18:23:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=20'w/Cache.java'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- w/Cache.java | 51 --------------------------------------------------- 1 file changed, 51 deletions(-) delete mode 100644 w/Cache.java diff --git a/w/Cache.java b/w/Cache.java deleted file mode 100644 index 18fa2f9..0000000 --- a/w/Cache.java +++ /dev/null @@ -1,51 +0,0 @@ -package w8; - -import java.util.HashMap; -import java.util.Map; - -public class Cache { - private final Map cache = new HashMap<>(); - - // 存入缓存 - public void put(K key, V value) { - cache.put(key, value); - } - - // 从缓存获取 - public V get(K key) { - return cache.get(key); - } - - // 移除缓存 - public V remove(K key) { - return cache.remove(key); - } - - // 清空缓存 - public void clear() { - cache.clear(); - } - - // 判断是否包含key - public boolean containsKey(K key) { - return cache.containsKey(key); - } - - // 获取缓存大小 - public int size() { - return cache.size(); - } - - // 测试 - public static void main(String[] args) { - Cache studentScore = new Cache<>(); - studentScore.put("张三", 90); - studentScore.put("李四", 85); - - System.out.println("张三的分数:" + studentScore.get("张三")); - System.out.println("缓存大小:" + studentScore.size()); - - studentScore.remove("李四"); - System.out.println("移除李四后,缓存是否包含李四?" + studentScore.containsKey("李四")); - } -} \ No newline at end of file