① Inherit different
public class Hashtable extends Dictionary implements maps public class HashMap extends Abstractmap implements map
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.
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.
④ 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.
⑤ hash values are used differently.
Hashtable directly uses the object's hashcode. The hash value is recalculated by the HashMap.
⑥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.
"Java" Hashtable and HashMap differences