LinkedHashMap in Java
LinkedHashMap is just like HashMap with an additional feature of maintaining an order of elements inserted into it. HashMap provided the advantage of quick insertion, search, and deletion but it never maintained the track and order of insertion which the LinkedHashMap provides where the elements can be accessed in their insertion order. Few important features of LinkedHashMap are as follows:
- A LinkedHashMap contains values based on the key. It implements the Map interface and extends the HashMap class.
- It contains unique elements (See this for details)...
- It may have one null key and multiple null values (See this for details).
- It is the same as HashMap with the additional feature that it maintains insertion order. For example, when we ran the code with HashMap, we got different order of elements (See this).
Declaration:
LinkedHashMap<Integer, String> lhm = new LinkedHashMap<Integer, String>();
Constructors in LinkedHashMap:
The LinkedHashMap accepts five types of constructors:
post a comment