The difference between hashmap 1.4 and 1.6

I have an application that works both on 1.4and on 1.6. The order of the elements printed in the version 1.6differs from 1.4. I used LinkedHashMapthat fixed the problem. Now this order is exactly the same as y 1.4. I did not find the 1.4source code HashMapexcept loading all jdk. Except for generic changes in new versions?

+3
source share
3 answers

The iteration order of elements in was HashMapnever guaranteed, so implementations could freely change it. This flaw has been eliminated LinkedHashMap.

, , Java 1.4.1... Java6 .

+4

HashMap undefined. , ( ) . , - , , .

LinkedHashMap HashMap .

+2

I assume that the implementation of HashMap has changed. HashMap does not guarantee any order, therefore you should not rely on it because it can change it without changes with new releases.

0
source

All Articles