Byte Interviewer: can you tell me in detail where HashMap7 and 8 are unsafe?

preface HashMap has some differences between JDK7 and JDK8, as shown below: The bottom layer of JDK7HashMap is array + linked list, while JDK8 is array + linked list + red black treeJDK7 adopts head plug method for capacity expansion, while JDK8 adopts tail plug methodThe rehash of JDK7 is all rehash, while JDK8 is part rehash.JDK8 is ...

Posted by Jmz on Tue, 08 Feb 2022 09:47:17 +0100

Java collection framework hash table HashMap source code analysis

๐Ÿ‘จโ€๐ŸŽ“ Blogger homepage: Java tribute dust collection Miraitow ๐Ÿ“† Creation time: ๐ŸŒด February 7, 2022 20:23-2:03 ๐ŸŒด ๐Ÿ“’ Content introduction: source code analysis of common collections. Later, there may be collections such as ArrayList ๐Ÿ“š Reference: [Xiao Liu speaks source code] โณ In short, I encourage you to watch the officials and try new t ...

Posted by joenjeru on Mon, 07 Feb 2022 19:43:31 +0100

HashMap1.8 analysis of underlying data structure, source code analysis and 1.7 how to form a circular linked list by header interpolation

One of the data structures commonly used in HashMap work. The underlying data structure is composed of array + linked list + red black tree, as shown in the figure below After knowing the data structure of HashMap, you will have some doubts. Why are there some linked lists, some red and black trees, and some have only one node? How do the link ...

Posted by manmanman on Mon, 07 Feb 2022 13:42:27 +0100

Hashmap's capacity expansion mechanism and element migration after capacity expansion - resize()

I HashMap Foundation HashMap inherits the AbstractMap abstract class and implements the Map, Cloneable and Serializable interfaces. Source code attribute of HashMap: public class HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Cloneable, Serializable { //The initial capacity is 16 static final int DEFAULT_IN ...

Posted by ultraviolet_998 on Mon, 31 Jan 2022 12:52:59 +0100

Interpretation of HashMap source code

This article is used to explore and learn the source code of HashMap and interpret the source code of HashMap. Mainly learn the idea of HashMap insertion and expansion. 1. Basic concepts HashMap is in jdk1 After 8, the internal data structure is optimized from the previous structure of "array + linked list" to the structure of &quo ...

Posted by rUmX on Sun, 30 Jan 2022 13:45:24 +0100

HashMap bottom hyperdetailed interpretation

HashMap bottom hyperdetailed interpretation First, substitute a question: how does the underlying HashMap find the corresponding stored array node through the Key? Look at the figure first to know what the underlying storage structure of HashMap is like In the first case, the length of the linked list at the node position of the same array i ...

Posted by DusterG20 on Fri, 28 Jan 2022 17:08:58 +0100

Why should the hashCode method be rewritten after the equals method is rewritten

Let's first look at the source code of the equals method and hashcode method of the Object class: public native int hashCode(); public boolean equals(Object obj) { return (this == obj); } From the code, we know that the created Object uses the equals method and hashcode method of Object without rewriting. From the source c ...

Posted by thebopps on Wed, 26 Jan 2022 11:45:37 +0100

HashMap source code analysis

HashMap source code analysis preface Tip: Here you can add the general contents to be recorded in this article: HashMap is a very common collection. Its data structure and design are very classic. As a java programmer, we must deeply understand its underlying implementation. Next, share with you by reading the source code of HashMap. ...

Posted by timbuckthree on Mon, 24 Jan 2022 12:18:49 +0100

HashMap introduction, that is, part of the source code analysis

brief introduction Introduction to HashMap HashMap is an implementation of Map interface based on hash table, which is used to store key value pairs. Due to the implementation of Map interface, HashMap allows null to be used as key and value, which is the same as other ordinary key values, that is, null can be used as the value of multiple ke ...

Posted by ranman on Mon, 24 Jan 2022 00:21:33 +0100

Non thread safe performance of HashMap

preface We all know that HashMap is thread unsafe, but what are the specific manifestations? Example 1 dead cycle This is the most frequently asked question in an interview, but in fact, this question has been asked in Java 1 Version 8 has been fixed. This problem exists only before version 1.7. The general reason is that when HashMap is exp ...

Posted by Otoom on Sun, 23 Jan 2022 07:22:50 +0100