Several traversal methods of HashMap? How to choose which one to use?

There are many HashMap traversal methods, and different JDK versions have different writing methods. Among them, JDK 8 provides 3 HashMap traversal methods, and breaks the embarrassment of “very bloated” previous traversal methods in one fell swoop. 1.Traversal before JDK 8 Before JDK 8, EntrySet and KeySet were mainly used for traversal. The specific implementation […]

HashMap Hash table initial understanding

With the support of a lofty goal, if you work non-stop, even if it is slow, you will definitely succeed. –Einstein 1. What is HashMap Also called a hash table, it is a very important data structure (array + linked list + red-black tree). It maps keys to values. It is a method of quickly […]

Containers (collections) in java, underlying principles of HashMap, differences between ArrayList, LinkedList, and Vector, reasons for hashMap loading factor 0.75

1. Containers in java Collections are mainly divided into two major interfaces: Collection and Map; the sub-interfaces of Collection include List and Set; the implementation classes of List collection include ArrayList, whose bottom layer is an array, and the bottom layer of LinkedList, which is a bidirectional acyclic list and Vector; the implementation classes of […]

HashMap — Research

HashMap Survey Preface Before JDK1.8 Zipper method: After JDK1.8 JDK1.7 VS JDK1.8 comparison Optimized the problem: What is the specific process of HashMap’s put method? How to implement the expansion and resize operation of HashMap? The source code leads to the conclusion. Notes Concept: What is Hashing Concept: What is a hash collision Why is […]

The process of storing elements in HashMap

jdk7: HashMap map = new HashMap(); After instantiation, the bottom layer creates a one-bit array Entry[] table with a length of 16. ···The put operation may have been performed multiple times··· map.put(key1,value1) First, the hashCode() method of the class where key1 is located is called to calculate the hash value of key1, and then the […]

Special topic on HashMap and LinkedHashMap

One, HashMap HashMapdoes not guarantee the insertion order, but when iterating through the loop, the output order will not change. The data structure of HashMap: array + singly linked list. When there are different objects with the same hashCode, the value will be appended in the form of a singly linked list. Arrays speed up […]

JDK1.8’s optimization of HashMap and its expansion mechanism through source code parsing 1.8

JDK 1.8 has made some optimizations to HashMap, mainly including the following improvements: Red-Black Tree: In JDK 1.8, when hash collision (multiple keys map to the same bucket) reaches a certain level, HashMap will convert the linked list into a Red-Black Tree to improve the performance of find, insert, and delete operations. This improvement is […]

Hashmap source code interpretation-java

There are many differences between the underlying layers of HashMap 1.8 and 1.7 1.8 The bottom layer is array + linked list + red tree (linked list adopts tail interpolation method) 1.7 The bottom layer is an array + a linked list (the linked list uses head interpolation, and an infinite loop may occur) The […]

ConcurrentHashMap source code topic

1. Preface HashMap is efficient and fast, but it is not safe. Especially in 2020, security is very important. There are currently three ways to provide secure maps on the market, namely hashtable: a relatively old thread safety mechanism. Only one thread can write operations at any time. It is now basically deprecated and replaced […]