Java-tip-hashmap

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.