HashMap vs. LinkedHashMap vs.TreeMap

All three classes implement the Map interface and offer mostly the same functionality. The most important difference is the order in which iteration through the entries will happen:
(1) HashMap
makes absolutely no guarantees about the iteration order. It can (and will) even change completely when new elements are added.
(2) 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.
(3) LinkedHashMap
will iterate in the order in which the entries were put into the map
Hash Table + Linked List: LinkedHashMap will take more memory. Each entry in a normal HashMap just has the key and the value. Each LinkedHashMap entry has those references and references to the next and previous entries.

HashMap vs. LinkedHashMap vs.TreeMap_第1张图片
屏幕快照 2017-09-17 上午2.15.29.png

你可能感兴趣的:(HashMap vs. LinkedHashMap vs.TreeMap)