Home  >  Q&A  >  body text

Java中HashMap,LinkedHashMap,WeakHashMap,HashTable,TreeMap等的区别?

Java中

HashMap
LinkedHashMap
WeakHashMap
HashTable
IdentityHashMap
TreeMap

的区别?

和它们各自的实现特点
比如HashMap用数组和链表来保存等。

阿神阿神2764 days ago907

reply all(2)I'll reply

  • 黄舟

    黄舟2017-04-18 09:50:24

    I wonder if you have ever learned data structure?

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-18 09:50:24

    HashMap: Map (Key-Value) type implemented based on Hash table
    TreeMap: Ordered Map (based on natural sorting of keys)
    LinkedHashMap: Ordered Map (based on insertion order sorting)
    WeakHashMap: Weak only holding keys Reference, so when the key is recycled, the record corresponding to the key can be automatically deleted.
    IdentityHashMap: Generally, in Map implementation, if the key values ​​are equal (equals is true), they are considered to be the same key. This Map uses the same object (reference) as the basis for judgment, and is not officially recommended for use.
    HashTable: Similar to HashMap, key or value can be null, thread-safe, old-fashioned implementation.
    Finally, I suggest that if you have this kind of problem, you can directly read the Java SE manual, which has a detailed introduction: Java SE API

    reply
    0
  • Cancelreply