In JDK 1.8 HashMap and Hashtable main differences are as follows:
- Different thread safety. HashMap thread-safe; Hashtable method is Synchronize of.
- key, value whether to allow null. The key and value are HashMap may be null, key allows only a null; Hashtable both the key and value is not null.
- Different iterators. The HashMap Iterator iterator is fail-fast; also uses the Hashtable enumerator iterator.
- The different hash calculation. HashMap calculated hash value; the Hashtable hashCode method using the key.
- The default initial size and expansion in different ways. HashMap default initial size 16, capacity must be an integer power of two, when the expansion capacity becomes 2 times the original; the Hashtable default initial size 11, when the expansion capacity becomes doubly original 2 1.
- Is there a method contains. HashMap contains no method; comprising the Hashtable contains method similar containsValue.
- Different parent. HashMap inherited from AbstractMap; Hashtable inherited from the Dictionary.
In-depth details, you can refer to:
- Java self-study guide
- Java interview questions summary PC client browser [Click here]
- Java mapping knowledge
- Java applets interview questions summary view, sweep the two-dimensional code
All resources resources are summarized in the public No.