Analysis of HashMap source code based on JDK8
preface
At present, the JDK version used is basically 1.8 or above. In most interviews, you will ask what is the difference between JDK7 and JDK8 versions of HashMap. HashMap is in jdk1 8, the red black tree is added on the basis of array + linked list. What are the benefits of doing so? In this paper, jdk1 8 version of HashMap to do a s ...
Posted by bradleyy on Tue, 08 Mar 2022 16:51:14 +0100
JDK1. 8 source code analysis of concurrenthashmap
JDK1. 8 source code analysis of concurrenthashmap
jdk1.8 container initialization
Source code analysis
There are five construction methods in the ConcurrentHashMap of jdk8. None of the four construction methods initialize the internal array, but deal with the initial values of some variablesThe array initialization of concurrent HashMap of j ...
Posted by reapfyre on Fri, 04 Mar 2022 09:25:47 +0100
JDK source code learning 06 currenthashmap analysis
JDK source code learning 06 currenthashmap analysis
The principle of CurrentHashMap is very complex. You can only record what you understand. As we all know, the thread safety implementation principle of CurrentHashMap is Synchronized+CAS. Now let's take a look.
Brief reading of notes
* Overview:
* The main design goal of this hash table is ...
Posted by nimzie on Fri, 04 Mar 2022 00:53:32 +0100
Reading HashMap source code from scratch
preface
I believe that this article is not the first time for my classmates to see articles about HashMap. Most of the online HashMap articles are not suitable for me, so I decided to understand the source code from scratch. I will use the relatively simple logic to convince myself to understand the source code. If you are interested, please l ...
Posted by racing_fire on Thu, 24 Feb 2022 16:55:12 +0100
HashCode & HashMap perturbation function, initialization capacity, load factor, expansion element splitting
Hashcode & HashMap perturbation function, initialization capacity, load factor, expansion element splitting
1. Why does hashcode use 31 as a multiplier?
String. The hashCode method of class is as follows:
public int hashCode() {
int h = hash;
if (h == 0 && value.lengt > 0) {
char[] val = value;
for (int ...
Posted by glowball on Tue, 22 Feb 2022 14:56:00 +0100
About concurrent HashMap from java7 to java8
Why use concurrenthashmap (the disadvantage of HashMap)
HashMap is the most commonly used Map class in Java. It has good performance and fast speed, but it can not guarantee thread safety. It can use null value as Key/value The thread insecurity of HashMap is mainly reflected in the dead loop when resizing and fast fail when using iterator In ...
Posted by McJepp on Sat, 19 Feb 2022 17:22:12 +0100
Three questions: understand hash table and hash conflict
What is a hash table?
Hash tables, also known as hash tables, are array based. This indirectly brings an advantage: the time complexity of search is O(1), and of course, its insertion time complexity is also O(1). There is also a disadvantage: the expansion cost is high after the array is created. There is a "mainstream" idea in hash ...
Posted by ghornet on Thu, 17 Feb 2022 20:40:36 +0100
HashMap source code and underlying data structure analysis
The official account of WeChat: Java essays Follow to learn more about Java related technology sharing. Questions or suggestions, welcome to the official account message!
Introduction to HashMap
HashMap is mainly used to store key value pairs. It is implemented based on the Map interface of hash table. It is one of the commonly used Jav ...
Posted by rubadub on Wed, 09 Feb 2022 01:42:55 +0100
Source Analysis of HashMap - Three main points (the reason for the capacity being 2nd power, calculation method of hash value and detailed expansion process)
1. Illustrating data structures
1. Infrastructure
(1) Arrays
Arrays are essentially a continuous block of memory that holds something in common. Array elements can be quickly positioned and manipulated through array subscripts. However, its insertion and deletion operations are inconvenient, requiring all elements following the insertio ...
Posted by DeeDee2010 on Tue, 08 Feb 2022 20:00:04 +0100
HashMap underlying principle and some problems induction
hashmap 1.7 capacity expansion occurs before element addition, and 1.8 capacity expansion occurs after element addition
Difference between hashmap 1.7 and 1.8 when adding new elements, 1.7 is added to the head and 1.8 is added to the tail. If it exceeds the preset value, it will turn into a red black tree
The element subscript calculation of ...
Posted by ben14 on Tue, 08 Feb 2022 14:33:17 +0100