As the documentation clearly states, HashMaps are unordered.
The enumeration order is determined by the hascodes of the keys.
If you want to preserve insertion order when enumerating the map, use LinkedHashMap
.
If you want enumeration order to follow the natural ordering of the keys, use TreeMap
.