What are the differences between a HashMap and a Hashtable in Java?

后端 未结 30 2430
青春惊慌失措
青春惊慌失措 2020-11-21 13:30

What are the differences between a HashMap and a Hashtable in Java?

Which is more efficient for non-threaded applications?

30条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-11-21 13:50

    1.Hashmap and HashTable both store key and value.

    2.Hashmap can store one key as null. Hashtable can't store null.

    3.HashMap is not synchronized but Hashtable is synchronized.

    4.HashMap can be synchronized with Collection.SyncronizedMap(map)

    Map hashmap = new HashMap();
    
    Map map = Collections.SyncronizedMap(hashmap);
    

提交回复
热议问题