The LinkedHashMap Class
LinkedHashMap extends HashMap. It maintains a linked list of the entries in the map, in the order in which they were inserted. This allows insertion-order iteration over the map.
LinkedHashMap is a generic class that has this declaration:
class LinkedHashMap<K, V>
- K specifies the type of keys
- V specifies the type of values.
LinkedHashMap defines the following constructors:
LinkedHashMap( )
- constructs a default LinkedHashMap.
LinkedHashMap(Map<? extends K, ? extends V> m)
- initializes the LinkedHashMap with the elements from m.
LinkedHashMap(int capacity)
- initializes the capacity.
LinkedHashMap(int capacity, float fillRatio)
- initializes both capacity and fill ratio. The meaning of capacity and fill ratio are the same as for HashMap. The default capactiy is 16. The default ratio is 0.75.
LinkedHashMap(int capacity, float fillRatio, boolean Order)
- The last form allows you to specify whether the elements will be stored in the linked list by insertion order, or by order of last access. If Order is true, then access order is used. If Order is false, then insertion order is used.
LinkedHashMap adds only one method to those defined by HashMap. This method is removeEldestEntry( ) and it is shown here:
protected boolean removeEldestEntry(Map.Entry<K, V> e)
This method is called by put( ) and putAll( ). The oldest entry is passed in e.