LinkedHashMap
It is exactly same as HashMap,except the following differences.
HashMap |
LinkedHashMap |
|
|
In the above, if we are replacing HashMap LinkedHashMap, the following is output.
{ Narayana=100, Sunny=800, Anitha=200, Vighnesh=500}
i.e. insertion order is preserve.
Note:- LinkedHashSet & LinkedHashMap are best suitable to implement cache applications.
Identity HashMap
This is exactly same as HashMap, except the following difference. In the use of HashMap JVM always uses.equals() method to identify duplicate keys. But the in the case of IdentitfyHashMap, JVM uses==(equal) operator to identify duplicate keys.
{ HashMap m = new HashMap (); integer i1 = new integer (10); integer i2 = new integer ( 10); m. put ( i1, "narayana"); m. put (i2, "anitha"); System.out.println(t); // 10= sunny } }
In this case JVM uses.equals() method to check duplicate keys. Hence i1.equals(i2) returns true these are duplicated. If we are replacing HashMap with identify HashMap then JVM uses “==” operator,instead of .equals() method.
i1==i2 returns false, and these are not duplicated. Hence both entries will be added to the Map.The output is [ 10= kalyan, 10= pavan].
Hello! I am Narayanaswamy founder and admin of narayanatutorial.com. I have been working in the IT industry for more than 12 years. NarayanaTutorial is my web technologies blog. My specialties are Java / J2EE, Spring, Hibernate, Struts, Webservices, PHP, Oracle, MySQL, SQLServer, Web Hosting, Website Development, and IAM(ForgeRock) Specialist
I am a self-learner and passionate about training and writing. I am always trying my best to share my knowledge through my blog.