LinkedHashMap source code analysis

Table of Contents I. Introduction 2. Source code analysis 2.1. Class structure 2.2. Member variables 2.3. Construction method 2.4. accessOrder 2.5. Adding elements 2.6. Get elements 2.7. Delete elements 2.8. Iterators 3. Simple implementation of LRU 1. Foreword HashMap element insertion is unordered. In order to make the traversal order and insertion order consistent, we […]

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 […]

HashMap vs TreeMap vs Hashtable vs LinkedHashMap

Map is an important data structure. This article will introduce how to use different Maps, such as HashMap, TreeMap, HashTable and LinkedHashMap. Map Overview There are four common Map implementations in Java, HashMap, TreeMap, HashTable and LinkedHashMap. We can use one sentence to describe each Map, as follows: HashMap: Based on hash table implementation, it […]

The underlying implementation of HashMap, LinkedHashMap, ConcurrentHashMap, ArrayList, and LinkedList.

The underlying implementation of HashMap, LinkedHashMap, ConcurrentHashMap, ArrayList, and LinkedList. HashMap related questions 1. Have you ever used HashMap? What is HashMap? Why do you use it? Used, HashMap is an asynchronous implementation of the Map interface based on hash tables. It allows null keys and null values, and HashMap relies on the design of […]

Feign encountered generic type erasure during serialization, causing it to become a LinkedHashMap during deserialization.

Feign encountered generic type erasure during serialization, causing it to become a LinkedHashMap during deserialization Failure background problem analysis Fix Fix 1: Avoid using generics Fix 2: Process when parsing data generics Fault background Suppose we have a Feign interface import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.SpringQueryMap; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.PostMapping; @FeignClient(name = “testJdkDateTimeRpcService”, url = “${query-current-service-provider.prevBaseUrl}”) public […]

In-depth analysis of Java Map: master HashMap, TreeMap, LinkedHashMap and ConcurrentHashMap

Map interface In Java, the Map interface is a general collection of key-value pairs, which allows us to use a pair of key-values to store and access data. The key-value pair can be stored in the Map through the put(key, value) method, and then the corresponding value can be obtained through the get(key) method. Commonly […]

June 12, 2023, LinkedHashMap, Hashtable, ConcurrentHashMap, TreeMap, TreeMap case

Implement sorting of values in HashMap package com.wz.work; import java.util.*; public class test01 { /** * Requirement: To sort the values in the HashMap * @param args */ public static void main(String[] args) { HashMap<String, Integer> map = new HashMap<>(); map.put(“Zhang San”,18); map.put(“Li Si”,20); map.put(“Wang Wu”,26); map.put(“Zhao Liu”,21); map.put(“Wu Qi”,19); map.put(“King Ba”,22); //Get the map […]

Java-Map collection HashMap collection LinkedHashMap collection TreeMap collection

Map Collection Overview of the Map collection interface Map<K,V> K: type of key; V: type of value Features of the Map collection Two-column collection, one key corresponds to one value Keys cannot be repeated, values can be repeated Basic use of Map collection public class MapDemo01 { public static void main(String[] args) { //Create collection […]