Difference between HashMap, LinkedHashMap and TreeMap

后端 未结 17 2139
醉话见心
醉话见心 2020-11-22 01:01

What is the difference between HashMap, LinkedHashMap and TreeMap in Java? I don\'t see any difference in the output as all the three

17条回答
  •  难免孤独
    2020-11-22 01:36

    • HashMap:

      • Order not maintains
      • Faster than LinkedHashMap
      • Used for store heap of objects
    • LinkedHashMap:

      • LinkedHashMap insertion order will be maintained
      • Slower than HashMap and faster than TreeMap
      • If you want to maintain an insertion order use this.
    • TreeMap:

      • TreeMap is a tree-based mapping
      • TreeMap will follow the natural ordering of key
      • Slower than HashMap and LinkedHashMap
      • Use TreeMap when you need to maintain natural(default) ordering

提交回复
热议问题