The lower level implementation of Java HashMap

Source: Internet
Author: User

Today, in the interview of the Gathering times, I say I have hashmap myself on my own understanding. After describing my own realization idea, the interviewer asks "HashMap" if the array is less efficient than the red-black tree? I was all at once. It is inefficient to use arrays, but it is true that JDK uses array + linked lists to store entities when compared to the source of the JDK.

Back, hurriedly looked at the source code, also compared to the JDK6 and JDK 8 hashmap, found something not quite right place. Originally, the original view is JDK 6. The JDK in this version is indeed stored using an array + linked list. But at JDK 8, in order to solve the collision, the JDK proposed a new way, that is, to specify a factor, the first is to use the array + linked list to store, when greater than this factor, the linked list into a red black tree. That is, the version of JDK 8 uses an array + linked list/red-black tree.

This week is still a bit busy. When you're done, write a blog post from the source to analyze the JDK 8 improvements.

PS: This is done by judging the proportion of storage entities, using different processing methods. Not only here. Also appears in the Array tool class. That is Arrays.sort (); The number of arrays is sorted by normal or fast.

Resources:

1, http://www.jetbrains.com/idea/webhelp/comparing-files.html

2, http://coderbee.net/index.php/java/20131018/519

3, http://developer.51cto.com/art/201404/437062.htm

The lower level implementation of Java 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.