Java - The LinkedHashMap Class

This class extends HashMap and 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. That is, when iterating a LinkedHashMap, the elements will be returned in the order in which they were inserted.

You can also create a LinkedHashMap that returns its elements in the order in which they were last accessed.

The LinkedHashMap class supports five constructors. The first form constructs a default LinkedHashMap:

LinkedHashMap( )

The second form initializes the LinkedHashMap with the elements from m:

LinkedHashMap(Map m)

The third form initializes the capacity:

LinkedHashMap(int capacity)

The fourth form initializes both capacity and fill ratio. The meaning of capacity and fill ratio are the same as for HashMap:

LinkedHashMap(int capacity, float fillRatio)

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(int capacity, float fillRatio, boolean Order)

Apart from the methods inherited from its parent classes, LinkedHashMap defines following methods:

SN

Methods with Description

1

void clear() Removes all mappings from this map.

2

boolean containsKey(Object key) Returns true if this map maps one or more keys to the specified value.

3

Object get(Object key) Returns the value to which this map maps the specified key.