Can I guarantee the same result if I use the values()
method?
Basically, LinkedHashMap#values
returns you a restricted view of the internal structure. And I'd venture to say it must give the same result. It's not explicitly stated in the docs
Returns a Set
view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa.
but the highlighted excerpt makes me think so.
"The same result" is more than a data collection: it includes the way the data should be iterated (the iterator). "changes to the map are reflected in the set" to me implies that both iterators share one algorithm, which, on the same piece of data, would result in the same behaviour.