OnJava8-Examples/containersindepth/LinkedHashMapDemo.java

28 lines
920 B
Java
Raw Normal View History

2015-09-07 11:44:36 -06:00
// containersindepth/LinkedHashMapDemo.java
2015-06-15 17:47:35 -07:00
// What you can do with a LinkedHashMap.
import java.util.*;
import com.mindviewinc.util.*;
public class LinkedHashMapDemo {
public static void main(String[] args) {
LinkedHashMap<Integer,String> linkedMap =
new LinkedHashMap<>(new CountingMapData(9));
2015-11-03 12:00:44 -08:00
System.out.println(linkedMap);
2015-06-15 17:47:35 -07:00
// Least-recently-used order:
linkedMap = new LinkedHashMap<>(16, 0.75f, true);
linkedMap.putAll(new CountingMapData(9));
2015-11-03 12:00:44 -08:00
System.out.println(linkedMap);
2015-06-15 17:47:35 -07:00
for(int i = 0; i < 6; i++) // Cause accesses:
linkedMap.get(i);
2015-11-03 12:00:44 -08:00
System.out.println(linkedMap);
2015-06-15 17:47:35 -07:00
linkedMap.get(0);
2015-11-03 12:00:44 -08:00
System.out.println(linkedMap);
2015-06-15 17:47:35 -07:00
}
2015-09-07 11:44:36 -06:00
}
/* Output:
2015-06-15 17:47:35 -07:00
{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}
2015-09-07 11:44:36 -06:00
*/