HashMap interview

  1. The difference between HashMap and Hashtable

Return the value of all values, and contains methods hashtable and hashmap have containsvalue method, which contains the underlying hashtable method is actually called. hashmap can save the key / value is null data, hashtable of key and value can not be empty, to obtain data for the empty hashmap the get (), may be value in itself save is empty, there may be current key does not exist return data, it can not get () to determine whether there is a key, the method should be used containsKey (); initialization hashmap hashtable size and 11 are the same, but when hashmap expansion will increase the size of n, and the hashtable size is increased n + 1, hashmap is thread safe, Hashtable is thread safe class, Hashtable methods are modified with key Synchronize, Synchronize object lock is used, performance is not so high hashmap in peacetime, meet hashmap High performance in single-threaded scenarios needs. hashtable of key does not support null, because the key will be directly hashtable hashcode calculation, and is null hashmap is set to a particular hash value, bitwise hashmap performed in the calculation of the hash value, the division is performed hashtable , HashMap is more concerned about the computational efficiency of the hash, traversal above, hashtable additional support Enumeration iterative way.

Guess you like

Origin www.cnblogs.com/java2048/p/12057397.html