HashMap vs LinkedHashMap vs TreeMap

0 votes

Can someone explain the difference between HashMap, LinkedHashMap, and TreeMap in Java? Along with this, please throw some light on Hashtable as well. Thank you in advance.

May 5, 2018 in Java by 93.lynn
• 1,600 points
1,430 views

1 answer to this question.

0 votes

Hi, there is no as such difference in their functionality as all three of them implement the Map interface but there lies a difference in the output they generate. To put it in simple terms:

HashMap: It is implemented based on the hashtable and there is no specific ordering on the keys as well as the values.

Hashtable is a class which inherits Dictionary class and implements the Map interface. It is basically an array of list type know as buckets. The positioning of each bucket is identified using the hashcode() and then it maps the unique keys to the values. It’s a synchronized class which do not contain any null key or value.

TreeMap: Its implementation is based on the red-black tree structure and follows the natural ordering of the key-value pairs.

LinkedHashMap: It works simplest among all by just following the insertion order of the key-value pairs.

answered May 5, 2018 by v.liyyah
• 1,300 points

Related Questions In Java

0 votes
2 answers

How is hashmap different from hashtable?

HashMap and HashTable: 1) Hashtable and Hashmap implement ...READ MORE

answered Aug 1, 2018 in Java by samarth295
• 2,220 points
6,477 views
0 votes
0 answers

Ho do I Iterate through a HashMap which contains duplicate values

What is the fastest and the best ...READ MORE

Apr 16, 2018 in Java by Daisy
• 8,140 points
821 views
+1 vote
1 answer

concat() vs “+” operator : In Java for String concatenation

Basically, there are two important differences between ...READ MORE

answered Apr 27, 2018 in Java by Rishabh
• 3,620 points
4,770 views
0 votes
1 answer

Comparable vs Comparator in Java

I think you are not alone who is ...READ MORE

answered May 11, 2018 in Java by code.reaper12
• 3,500 points
1,064 views
0 votes
1 answer

@Component vs @Repository vs @Service in Spring Framework

As you might be knowing, all these ...READ MORE

answered May 29, 2018 in Java by geek.erkami
• 2,680 points
3,676 views
0 votes
2 answers

Ho do I Iterate through a HashMap which contains duplicate values

for (Map.Entry<String, String> item : params.entrySet()) { ...READ MORE

answered Jul 24, 2018 in Java by samarth295
• 2,220 points
5,321 views
0 votes
1 answer

How to convert or cast hashmap to JSON object in Java, and again convert JSON object to JSON string?

You can use: new JSONObject(map); READ MORE

answered Jun 27, 2018 in Java by Akrati
• 3,190 points
7,024 views
0 votes
2 answers

How do we convert JSON to Map in Java

When you don't know structure of json. ...READ MORE

answered Oct 31, 2018 in Java by Sushmita
• 6,920 points
6,067 views
0 votes
2 answers

How to iterate in a HashMap in Java?

Iterating using Iterator. Using Generics: Map<Integer, Integer> map = ...READ MORE

answered Aug 28, 2019 in Java by Sirajul
• 59,230 points
1,035 views
0 votes
1 answer

Spring AOP vs AspectJ AOP

Well, below I have listed down few ...READ MORE

answered Sep 10, 2018 in Java by v.liyyah
• 1,300 points
1,382 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP