LinkedHashMap in Java

LinkedHashMap in Java

LinkedHashMap extends HashMap class and implements Map interface, so it inherit features of HashMap along with some other features which distinguish it from HashMap. A LinkedHashMap is a combination of hash table and linked list. It maintains a doubly-linked list running through all of its entries to maintain insertion order.

Followings are the features of LinkedHashMap.

  1. It stores key-value pairs.
  2. It contains unique key.
  3. Similar to HashMap, it allows one null key and multiple null values.
  4. Insertion order is maintained.
  5. Performance is likely to be just slightly below that of HashMap, due to the added expense of maintaining the linked list with one exception, Iteration over the LinkedHashMap requires time proportional to the size of the map, regardless of its capacity. While, Iteration over a HashMap is likely to be more expensive, requiring time proportional to its capacity.
  6. It is not synchronized.

LinkedHashMap provides following constructors.

[table “” not found /]

Example of LinkedHashMap.

Output

Leave a Reply

Your email address will not be published. Required fields are marked *