Difference between HashMap, LinkedHashMap and TreeMap
HashMapmakes absolutely no guarantees about the iteration order. It can (and will) even change completely when new elements are added.
TreeMapwill 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.
LinkedHashMapwill iterate in the order in which the entries were put into the map