When I was going through a example code which has ListViews I came up with LinkedHashMap
.
What is a LinkedHashMap
and where can we use it and how? I went through several articles but did not understand fully. Is it necessary when creating ListView
. What is the connection between ListViews and LinkedHashMaps? Thank you.

- 1,560
- 2
- 26
- 36

- 6,622
- 30
- 95
- 182
-
6We can tell you, but it's always better when you read the [docs](http://docs.oracle.com/javase/7/docs/api/java/util/LinkedHashMap.html) – Nir Alfasi Aug 18 '14 at 06:33
-
1this one as well [android docs](http://developer.android.com/reference/java/util/LinkedHashMap.html) – Michael Shrestha Aug 18 '14 at 06:35
4 Answers
For Simplicity, let us understand what is the difference between HashMap and LinkedHashMap.
HashMap: It gives output in Random orders means there is no proper sequence how we have inserted values.
whereas
LinkedHashMap: It gives output in sequential order.
Let us see a small example: with HashMap
// suppose we have written a program
.
.
// now use HashMap
HashMap map = new HashMap(); // create object
map.put(1,"Rohit"); // insert values
map.put(2,"Rahul");
map.put(3,"Ajay");
System.out.println("MAP=" +map); //print the output using concatenation
//So the output may be in any order like we can say the output may be as:
Map={3=Ajay,2=Rahul,1=Rohit}
but this is not the case in LinkedHashMap Just replace the "HashMap" with "LinkedHashMap" in the above code and see it will display the output in Sequential order like 1=Rohit will be displayed first then the others in sequence.

- 618
- 1
- 11
- 23
The docs are here. But its basically a HashMap that also has a linked list, so you can have a consistently ordered iteration through it. Note that this means removals may be O(n) time because you need to remove it from both data structures.

- 90,003
- 9
- 87
- 127
LinkedHashMap is hashmap. But it maintains order of insertion. But HashMap doesnt maintain order.

- 1,983
- 3
- 14
- 26
Hi Linked Hash Map is a Map which stored key value pair, Linked Hash Map add the values may very slow, But while retrieving the values is very easy. For fast retrieval of values we could prefer Linked Hash Map.

- 19
- 2