HashMap Basic Lookup process: First use Key.hashcode () to generate a hash value, based on the hash value to determine where key is located in the array, and then use the Key.equals () method to find the specified key.
1. What conditions should a custom object meet to be a HashMap key? The key that you want to be a hashmap must satisfy two conditions: 1) override the Hashcode () method , and the Hashcode () of an object determines where the object is stored in the hash table note: The Hashcode () method of object is based on the address Computed. 2) override the Equals () method, and the Equals () method determines whether the object is present in the hash table. Note: the Equals () method of object simply compares address 2. On the Android platform HashMap loading factor and expansion HashMap although it provides a constructor that can specify the loading factor, it is not used in the actual implementation . its loading factor is always 0.75f.
If the actual number of keys is too large, it will result in more hash of the collision, thus affecting the search efficiency. When size > capacity * Loading Factor, HashMap will be expanded.
The HashMap expansion steps are as follows: 1. Request a new array, twice times the size of the old 2. Rehash, put the existing item in the new hash table
HashMap expansion is a time-consuming operation, so when we use HashMap, we try to specify the appropriate capacity to avoid expansion.
Java-tip-hashmap