2015-04-20 15:36:01 -07:00
|
|
|
|
//: containers/LinkedHashMapDemo.java
|
2015-05-29 14:18:51 -07:00
|
|
|
|
// <20>2015 MindView LLC: see Copyright.txt
|
2015-04-20 15:36:01 -07:00
|
|
|
|
// What you can do with a LinkedHashMap.
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import net.mindview.util.*;
|
|
|
|
|
import static net.mindview.util.Print.*;
|
|
|
|
|
|
|
|
|
|
public class LinkedHashMapDemo {
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
LinkedHashMap<Integer,String> linkedMap =
|
2015-05-05 11:20:13 -07:00
|
|
|
|
new LinkedHashMap<>(new CountingMapData(9));
|
2015-04-20 15:36:01 -07:00
|
|
|
|
print(linkedMap);
|
|
|
|
|
// Least-recently-used order:
|
2015-05-05 11:20:13 -07:00
|
|
|
|
linkedMap = new LinkedHashMap<>(16, 0.75f, true);
|
2015-04-20 15:36:01 -07:00
|
|
|
|
linkedMap.putAll(new CountingMapData(9));
|
|
|
|
|
print(linkedMap);
|
|
|
|
|
for(int i = 0; i < 6; i++) // Cause accesses:
|
|
|
|
|
linkedMap.get(i);
|
|
|
|
|
print(linkedMap);
|
|
|
|
|
linkedMap.get(0);
|
|
|
|
|
print(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}
|
|
|
|
|
*///:~
|