31 lines
1.1 KiB
Java
31 lines
1.1 KiB
Java
// understandingcollections/LinkedHashMapDemo.java
|
|
// (c)2016 MindView LLC: see Copyright.txt
|
|
// We make no guarantees that this code is fit for any purpose.
|
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
|
// What you can do with a LinkedHashMap
|
|
import java.util.*;
|
|
import onjava.*;
|
|
|
|
public class LinkedHashMapDemo {
|
|
public static void main(String[] args) {
|
|
LinkedHashMap<Integer,String> linkedMap =
|
|
new LinkedHashMap<>(new CountMap(9));
|
|
System.out.println(linkedMap);
|
|
// Least-recently-used order:
|
|
linkedMap = new LinkedHashMap<>(16, 0.75f, true);
|
|
linkedMap.putAll(new CountMap(9));
|
|
System.out.println(linkedMap);
|
|
for(int i = 0; i < 6; i++) // Cause accesses:
|
|
linkedMap.get(i);
|
|
System.out.println(linkedMap);
|
|
linkedMap.get(0);
|
|
System.out.println(linkedMap);
|
|
}
|
|
}
|
|
/* Output:
|
|
{0=A0, 1=B0, 2=C0, 3=D0, 4=E0, 5=F0, 6=G0, 7=H0, 8=I0}
|
|
{0=A0, 1=B0, 2=C0, 3=D0, 4=E0, 5=F0, 6=G0, 7=H0, 8=I0}
|
|
{6=G0, 7=H0, 8=I0, 0=A0, 1=B0, 2=C0, 3=D0, 4=E0, 5=F0}
|
|
{6=G0, 7=H0, 8=I0, 1=B0, 2=C0, 3=D0, 4=E0, 5=F0, 0=A0}
|
|
*/
|