I have application which runs on both 1.4 and 1.6. Order of elements is getting printed in 1.6 version is different than 1.4. I used LinkedHashMap which fixed the problem. Now this order is exactly same as of 1.4. I didn't find 1.4 source code of HashMap except downloading entire jdk . Except generic whats been changed in newer versions?
The iteration order of elements in HashMap was never guaranteed, so implementations were free to change it. This shortcoming has been remedied by LinkedHashMap.
Such a change might be caused by e.g. the complete revamping of the hashing algorithm in Java 1.4.1... but then again, we also noticed such a change upon migrating our project to Java6 so there was a change in that version too.
The order of iteration in HashMap is undefined. That means it can (and does) change all the time. It depends not only on the code, but on the values of the hash codes of objects, which themselves can differ not only from version to version, but even from run to run.
LinkedHashMap exists specifically as a HashMap alternative with a predictable iteration order.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With