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.

  Java Book 

  1. The LinkedHashMap Class
  2. new LinkedHashMap()
  3. new LinkedHashMap(int initialCapacity, float loadFactor, boolean accessOrder)
  4. clear()
  5. containsKey(Object key)
  6. containsValue(Object value)
  7. get(Object key)
  8. put(K key, V value)
  9. remove(Object key)
  10. LinkedHashMap size()
  11. LinkedHashMap values()