HashMap makes absolutely not guarantees about the iteration order. It can (and will) even change completely when new elements are added.
TreeMap will iterate according to the “natural ordering” of the keys according to their compareTo()method (or an externally supplied Comparator). Additionally, it implements the SortedMapinterface, which contains methods that depend on this sort order.
LinkedHashMap will iterate in the order in which the entries were put into the map

Advertisements