Java LinkedHashMap

LinkedHashMap is similar to HashMap with an additional feature of maintaining insertion order. 

It allows us to quick insert, update and delete of elements like HashMap.

LinkedHashMap can have only one null key and multiple null values like of HashMap.

Syntax:

LinkedHashMap<Key, Value>();

Note:

  1. HashMap doesn’t maintain insertion order order.
  2. TreeMap by default sort the entries in ascending order of keys.
  3. LinkedHashMap maintains the insertion order of entries.

LinkedHashMap Example:

Below is the example to create LinkedHashMap, add elements and print all on the screen using iterator.

LinkedHashMap Methods:

put() → Adding an element to the LinkedHashMap using key.

replace() → method with two parameters will return the old key which got replaced.

replace() → method with three parameters will return true if got replaced by same key and old value passed in method parameter.

size() → method will return the number of key value pairs

containsKey() → method will return true if specified key is found in LinkedHashMap.

containsValue() → method will return true if specified value is found in 
get() method will return the specified value depending on the key passed as a parameter.

Clear() → method will remove all the key value pairs from LinkedHashMap and make it empty.

values() → method will return the collection of value in the LinkedHashMap.

keySet() → method will return the collection of key in the LinkedHashMap.

OUTPUT:

Imran Khan

Specialist Master (Architect) with a passion for cutting-edge technologies like AEM (Adobe Experience Manager) and a proven track record of delivering high-quality software solutions.

  • Languages: Java, Python
  • Frameworks: J2EE, Spring, Struts 2.0, Hibernate
  • Web Technologies: React, HTML, CSS
  • Analytics: Adobe Analytics
  • Tools & Technologies: IntelliJ, JIRA

🌐 LinkedIn

📝 Blogs

📧 Imran Khan