Hashtable and HashMap differences
First, inheritance is different.
Implements MAP
Implements MAP
Second
The methods in Hashtable are synchronous, and the methods in HashMap are not synchronized by default. In the context of multi-threaded concurrency, you can use Hashtable directly, but to use hashmap, you need to increase the synchronization process.
Third
In Hashtable, both key and value do not allow null values.
In HashMap, NULL can be used as a key with only one key, and one or more keys can have a value of NULL. When the Get () method returns a null value, it can indicate that the key is not in the HashMap, or that the value corresponding to the key is null. Therefore, the get () method cannot be used in HashMap to determine whether a key exists in HashMap and should be judged by the ContainsKey () method.
Four, the internal implementation of the two traversal methods is different.
Hashtable and HashMap all use the Iterator. For historical reasons, Hashtable also used the enumeration approach.
Fifth
Hash values are used differently, Hashtable directly using the object's hashcode. The hash value is recalculated by the HashMap.
Sixth
Hashtable and hashmap their two internal implementations of the array's initial size and the way the capacity is expanded. The default size of the hash array in Hashtable is 11, and the increment is old*2+1. The default size of the hash array in HashMap is 16, and must be a 2 index.
The difference between JAVA HashMap and Hashtable