Java Linked HashMap - Smart Tech Guides

Latest

Hi this is Sravan Kumar from India. SMART TECH GUIDES is a technical blog. it helps you to learn about Java topics, frameworks and tools like Jenkins, GitHub & related explanations, data base related topics. All these Explanations are explained in simple and understandable manner.

Subscribe Us

SMART TECH GUIDES

Java Linked HashMap

 

Linked HashMap

The Java Linked HashMap is not a part of the Collection interface and it is available in java.util package. 

Linked HashMap class extends HashMap class and implements the Map interface.

The Linked HashMap Class is just like HashMap with an additional feature it maintains insertion order.

Java Linked HashMap contains unique elements.

Java Linked HashMap contains values based on the key.

Java Linked HashMap may have one null key and multiple null values.

Java Linked HashMap is non synchronized.


Creation of Linked HashMap:

Syntax:

LinkedHashMap <k, V> map=new LinkedHashMap <K, V>(int initialcapacity);

LinkedHashMap <k, V> map=new LinkedHashMap <K, V>();

Here, k represents key, v represent value.

 

Methods of LinkedHashMap:

Some of the important methods in LinkedHashMap

put(k, v): this method is used to associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced.

clear(): this method is used to removes all of the mappings from this map. The map will be empty after this call returns.

Remove(): this method is used to removes the mapping for the specified key from this map if present.

keySet(): this method returns the Set view containing all the keys.

get(Object key): this method returns the object that contains the value associated with the key.

getOrDefault(Object key, integer default value): this method returns the value to which the specified key is mapped, or default value if this map contains no mapping for the key.


Java Program:


Output:

No comments:

Post a Comment