I have an instance of LinkedHashMap
. LinkedHashMap
preserves the insertion order. I need to get the values of this map and I need them to be in the same order. So if I call values()
method on this LinkedHashMap
,
the Collection
that I retrieve from values()
method will guarantee the insertion order?
Asked
Active
Viewed 172 times
4
-
I think yes. You could verify it quickly. – pnv Oct 22 '14 at 08:19
-
The answer is yes as can be seen here [enter link description here][1] [1]: http://stackoverflow.com/a/2889800/3584765 – Eypros Oct 22 '14 at 08:21
-
1Note that demonstrating that a particular implementation preserves order does *not* answer this question. It is really a question about the API definition. – Raedwald Oct 22 '14 at 08:25
-
@Duncan I overread that my fault -> no exact duplicate – JBA Oct 22 '14 at 08:26
-
@KPJ If the map is modified while an iteration over the collection is in progress(except through the iterator's own remove operation),the results of the iteration are undefined. – Keshav Sharma Oct 22 '14 at 08:32
1 Answers
3
Yes, in the source code of LinkedHashMap resides an inner class LinkedValues which remains the order. An object of this class is returned by values().

Lukas Glowania
- 498
- 6
- 12