-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedHashMapDemo.java
More file actions
28 lines (24 loc) · 1.03 KB
/
Copy pathLinkedHashMapDemo.java
File metadata and controls
28 lines (24 loc) · 1.03 KB
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
28
package MapPackage;
import java.util.LinkedHashMap;
public class LinkedHashMapDemo {
public static void main(String[] args) {
//linkedHashMap以插入顺序返回键值对
LinkedHashMap<Integer, String> linkedMap = new LinkedHashMap<>(new CountingMapData(9));
System.out.println(linkedMap);
System.out.println("=================");
//LRU least-recently-order 最近最少未使用
//设置初始容量和扩容参数
linkedMap = new LinkedHashMap<>(16, 0.75f, true);
linkedMap.putAll(new CountingMapData(9));
//设置最近最少未使用,于是没有被访问的元素就会出现在队列的最前面,适合一些需要定期清理的程序
System.out.println(linkedMap);
System.out.println("-----------------------------");
for (int i = 0; i < 6; i++) {
linkedMap.get(i);
}
System.out.println(linkedMap);
System.out.println("====");
linkedMap.get(0);
System.out.println(linkedMap);
}
}