Difference between HashMap, LinkedHashMap and TreeMap
HashMap
makes absolutely no 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 theircompareTo()
method (or an externally suppliedComparator
). Additionally, it implements theSortedMap
interface, which contains methods that depend on this sort order.LinkedHashMap
will iterate in the order in which the entries were put into the map
taken from:
https://stackoverflow.com/questions/2889777/difference-between-hashmap-linkedhashmap-and-treemap