java.util.LinkedHashMap class
java.util.LinkedHashMap class
- We can store group of objects in the form of key-value pairs in LinkedHashMap object.
- Both key and values are objects only.
- Keys can be unique and values can be duplicate.
- Here group of objects means, it can allow us to store same type of objects and different type of objects.
- Same type means, assuming that all objects are in the form of integer types.
- Different type means, assuming that all objects are in the form of integer, float, String, Student and Customer types also.
- Size will increase dynamically.
Program : Example on LinkedHashMap class
Program name : LHMDemo1.java
Output :
{1=Nireekshan, 2=Sravan, 10=Mouli, 9=Mohan, 3=Hari}
import java.util.LinkedHashMap;
class LHMDemo1
{
public static void main(String args[])
{
LinkedHashMap linkedHashMap = new LinkedHashMap();
linkedHashMap.put(1, "Nireekshan");
linkedHashMap.put(2, "Sravan");
linkedHashMap.put(10, "Mouli");
linkedHashMap.put(10, "Mouli");
linkedHashMap.put(9, "Mohan");
linkedHashMap.put(3, "Hari");
System.out.println(linkedHashMap );
}
}
Compile : javac LHMDemo1.java
Run : java LHMDemo1
Output :
{1=Nireekshan, 2=Sravan, 10=Mouli, 9=Mohan, 3=Hari}
--------------------------------------------------------------------------------------------
Thanks for your time.
Nireekshan