Does a HashMap retain the order of its elements on the next read if it is constructed as a LinkedHas

Posted by javanix on Stack Overflow See other posts from Stack Overflow or by javanix
Published on 2010-04-13T22:01:25Z Indexed on 2010/04/13 22:02 UTC
Read the original article Hit count: 292

Suppose I have a Java method that returns a HashMap object.

Because a LinkedHashMap is a subclass of HashMap, I can return a LinkedHashMap from this method just fine.

On the next "read" action (no adding/removing/modifying of K/V pairs), would iterating over the keys of the resulting method (which returns a HashMap) go in the same order as the originating LinkedHashMap, even though the HashMap lacks the key links?

© Stack Overflow or respective owner

Related posts about java

Related posts about hashmap