Java feature-hashmap

Source: Internet
Author: User

Want to share an understanding of HashMap:

We first need to know the composition of a HashMap object, the general understanding is: A map contains a number of key-value pairs, together is a key-value pairs of arrays;

Probably understand that, but one thing to say, in this array of key-value pairs, the memory space of each element of the array is not necessarily the same as the key value, this depends on the situation.

We understand the hashmap of the implementation of the principle of understanding why.

=======================================================

We create a hashmap usually as follows:

HASHMAP MP = new HashMap ();

When we use the map put (Key,value) method to fill in the value, HashMap will pass the key you passed in to calculate a hash value, no matter how long you pass the string, will be calculated by the value of an int class type, collectively known as the hash value, The hash value is then processed to get an array subscript. The system will enclose the key and value we passed into a entry object in this address. The problem is that, different hash to calculate the array subscript, the result may be the same, and this subscript has been used before, stored another pair of key values; HashMap will add a storage unit behind this subscript element to store the oldest key value (the new one is placed in its original position). These two pairs of key values are linked in an array element by a linked list.

=================

Say so much first,,, and later add

Java feature-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.