LinkedHashMap is a Hash table and linked list implementation of the Map interface in the Java Standard library. This implementation provides a predictable iteration order, in contrast with the unspecified ordering provided by HashMap, which is normally the order in which keys were inserted into the map.
Questions tagged [linkedhashmap]
703 questions
19
votes
2 answers
Method to extract all keys from LinkedHashMap into a List
I am working with many LinkedHashMap that are either LinkedHashMap, LinkedHashMap or LinkedHashMap.
My objective is to find or create a method that will return a List with all the keys in the above…

user2763361
- 3,789
- 11
- 45
- 81
18
votes
4 answers
How do you group elements in a List to a Map> while retaining order?
I have a List of Google PlaceSummary objects taken from the Google Places API. I'd like to collect and group them by their Google Place ID, but also retain the order of the elements. What I thought would work would be:
Map

James Murphy
- 800
- 1
- 15
- 29
18
votes
6 answers
How to implement ConcurrentHashMap with features similar in LinkedHashMap?
I have used LinkedHashMap with accessOrder true along with allowing a maximum of 500 entries at any time as the LRU cache for data. But due to scalability issues I want to move on to some thread-safe alternative. ConcurrentHashMap seems good in that…

DKSRathore
- 3,043
- 6
- 27
- 36
16
votes
1 answer
Is it dead code in LinkedHashMap in JDK11?
I am reading LinkedHashMap source code in JDK 11 and I found a piece of dead code(I'm not sure)
As we all know, LinkedHashMap use a doubly linked list to preserve the order of all the elements.It has a member called accessOrder
final boolean…

DamonChiu
- 193
- 3
16
votes
4 answers
How to sort a LinkedHashMap by value in decreasing order in java stream?
To sort it int ascending order I can use:
myMap.entrySet().stream()
.sorted(Map.Entry.comparingByValue())
.collect(Collectors.toMap(Entry::getKey, Entry::getValue));
How can I do it in decreasing order?

Oxydron
- 310
- 1
- 2
- 10
15
votes
3 answers
How to traverse Linked Hash Map in reverse?
Possible Duplicate:
Iterating through a LinkedHashMap in reverse order
How to traverse Linked Hash Map in a reverse order? Is there any predefined method in map to do that?
I'm creating it as follows:
LinkedHashMap map = new…

Jagadeesh
- 2,730
- 6
- 30
- 45
15
votes
6 answers
When to use linkedhashmap over hashmap in java?
What are the practical scenario for choosing among the linkedhashmap and hashmap? I have gone through working of each and come to the conclusion that linkedhashmap maintains the order of insertion i.e elements will be retrieved in the same order as…

nikhil
- 877
- 3
- 11
- 36
14
votes
3 answers
How do I get a keyIterator for a LinkedHashMap?
By looking at the source code for LinkedHashMaps from Sun, I see that there is a private class called KeyIterator, I would like to use this. How can I gain access?

Bobby
- 18,217
- 15
- 74
- 89
13
votes
4 answers
LinkedHashMap LIFO or FIFO?
Is LinkedHashMap LIFO or FIFO in nature?
If my map is of the form:
map.put(1,"one");
map.put(2,"two");
what would be the order if I was to iterate on the map using keyset??
EDIT: I think I did actually confuse two different concepts. Let me…

BlahBlah
- 275
- 1
- 5
- 15
12
votes
5 answers
Why doesn't LinkedHashMap provide access by index?
From Javadoc:
Hash table and linked list implementation of the Map interface, with predictable iteration order. This implementation differs from HashMap in that it maintains a doubly-linked list running through all of its entries.
If it is so, then…

Eternal Noob
- 2,717
- 5
- 27
- 41
12
votes
1 answer
Using Collectors.toMap to return a LinkedHashMap
How can I convert this:
return this.subjects.entrySet()
.stream()
.collect(Collectors.toMap(e -> getArtistryCopy(e.getKey()), Map.Entry::getValue));
To return a LinkedHashMap instead of a map?
If you need to know,…

John Lexus
- 3,576
- 3
- 15
- 33
12
votes
2 answers
What is purpose of 'accessOrder' field in LinkedHashMap?
There is a field in used by LinkedHashMap.java is:
final boolean accessOrder;
A constructor of LinkedHashMap is:
public LinkedHashMap(int initialCapacity,
float loadFactor,
boolean accessOrder) {
…

my name is GYAN
- 1,269
- 13
- 27
12
votes
7 answers
Building ordered JSON String from LinkedHashMap
I had a need for having Key/Value pairs in the order of my insertion, so I opted to use LinkedHashMap over HashMap. But I need to convert the LinkedHashMap into a JSON String where the order in the LinkedHashMap is maintained in the string.
But…

Karthic Rao
- 3,624
- 8
- 30
- 44
12
votes
3 answers
Get the first item of linkedhashmap
I am using LinkedHashMap. I will always process the first value and that can be deleted (if possible) so that during the next iteration I will again take the same first value from the map to process. What can I use to get the first value.

PrabhaT
- 858
- 3
- 10
- 22
10
votes
5 answers
Find keys that have at least n elements in common with another key, containing list
I have a LinkedHashMap of >. I am building the Map, so maybe there is a better approach to organizing all the data.
I am trying to get the keys that have a common list, with at least 2 elements in common in each lists.
For…

kanadianDri3
- 349
- 2
- 14