Java SE API

LinkedHashMap access-order constructor

Construct a map whose encounter order can reflect recent accesses. This alone does not bound its size.

Formal Syntax & Structure

java syntaxjava
LinkedHashMap(int initialCapacity, float loadFactor, boolean accessOrder)

Parameters & Attributes

NameTypeDescription
initialCapacityintInitial capacity.
loadFactorfloatLoad factor.
accessOrderbooleanTrue for access order, false for insertion order.

Working Example

Example Snippetjava
import java.util.*;public class Main {    enum Zone { NORTH, SOUTH }    public static void main(String[] args) {        Map<Zone, Integer> counts = new EnumMap<>(Zone.class);        counts.put(Zone.SOUTH, 2);        counts.put(Zone.NORTH, 5);        System.out.println(counts);        Map<String, Integer> recent = new LinkedHashMap<>(16, 0.75f, true);        recent.put("A", 1); recent.put("B", 2); recent.get("A");        System.out.println(recent.keySet());    }}
Java Reference