the difference between HashMap and Hashtable
1.HashTable method is synchronous, HashMap is not synchronized, so in multi-threaded occasions to do hands-on synchronization hashmap This difference is like vector and ArrayList.
2.HashTable does not allow null values (neither key nor value), HashMap allows null values (both key and value can be)
3. The way they traverse is much the same, Hashtable is only a elements way more than HashMap.
Both Hashtable and HashMap can return a collection through the values () method, and then traverse the process.
Both can also return a set through the EntrySet () method, and then perform traversal processing.
4.HashTable use Enumeration,hashmap with iterator.
5. Using different hash values, Hashtable directly uses the object's hashcode. The HashMap then recalculates the hash value and is used instead of the modulo.
The default size of the hash array in 6.HashTable is 11, and the increment is 2*old+1. The default size of the hash array in HashMap is 16, and must be a 2 index.
7.HashTable is based on the dictionary class, and HashMap is based on the Abstarctmap class.
the key in HashMap can be any object or data type.
1. can be null, but cannot be a mutable object, if it is a Mutable object, the object's properties change, then the object's hashcode also changed accordingly, so that the next time can not find the existing map data.
2. If a mutable object is used as a key in HashMap, be careful not to change its hash value when changing the state of the object. We only need to ensure that the change of the member variable guarantees that the hash value of the object will be constant.
Hashtable is thread-safe.
Hashtable is thread-safe, and its implementation is decorated with the addition of the Synchronized keyword on the corresponding method, which is slow to execute because the object lock needs to be obtained when executing this method. So now, if you want to keep the thread safe, use Concurrenthashmap.