Java utils collections: Map

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 their compareTo() method (or an externally supplied Comparator). Additionally, it implements the SortedMap 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

hashtables.JPG

taken from:

https://stackoverflow.com/questions/2889777/difference-between-hashmap-linkedhashmap-and-treemap

Leave a Reply

Your email address will not be published. Required fields are marked *