The difference between HashMap and HashTable

1. 继承和实现区别
   Hashtable是基于陈旧的Dictionary类,完成了Map接口, which is now obsolete in Jdk 1.7;HashMap是Java 1.2引进的Map接口的一个实现(HashMap继承于AbstractMap,AbstractMap完成了Map接口)。
2. synchronization or thread-safe
   HashTable的方法是同步的,HashMap是未同步,所以在多线程场合要手动同步HashMap。
3. Null keys and null values
   HashTable不允许null值(key和value都不可以),HashMap允许null值(key和value都可以)。
4. Iterating the values
   Hashmap使用iterator. HashTable is the only class other than vector which uses enumerator to iterate the values of HashTable object.
5. size
   HashTable中hash数组默认大小是11,增加的方式是 old*2+1。HashMap中hash数组的默认大小是16,而且一定是2的指数。
6. Fail-fast iterator
   The iterator in Hashmap is fail-fast iterator while the enumerator for Hashtable is not.
7. Performance
   Hashmap is much faster and uses less memory than Hashtable as former is unsynchronized . Unsynchronized objects are often much better in performance in compare to synchronized object like Hashtable in single threaded environment.

你可能感兴趣的:(The difference between HashMap and HashTable)