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 4, 2018 in Java by 93.lynn
• 1,560 points
236 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 4, 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,190 points
671 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,050 points
52 views
0 votes
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,540 points
924 views
0 votes
1 answer

Comparable vs Comparator in Java

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

answered May 10, 2018 in Java by code.reaper12
• 3,450 points
125 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,320 points
732 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,190 points
145 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,150 points
1,793 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,880 points
159 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 in Java by Sirajul
• 25,180 points
46 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
233 views