-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLRUCacheTest.java
More file actions
27 lines (25 loc) · 877 Bytes
/
Copy pathLRUCacheTest.java
File metadata and controls
27 lines (25 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com.al.lru_cache;
public class LRUCacheTest {
public static void main(String[] args) {
LRUCache cache = new LRUCache( 2 /* 缓存容量 */ );
cache.put(1, 1);
try {
System.out.println(cache.keys());
} catch (Exception e) {
e.printStackTrace();
}
cache.put(2, 2);
System.out.println(cache.get(1)); // 返回 1
cache.put(3, 3); // 该操作会使得关键字 2 作废
try {
System.out.println(cache.keys());
} catch (Exception e) {
e.printStackTrace();
}
cache.get(2); // 返回 -1 (未找到)
cache.put(4, 4); // 该操作会使得关键字 1 作废
cache.get(1); // 返回 -1 (未找到)
cache.get(3); // 返回 3
cache.get(4); // 返回 4
}
}