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