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
In depth understanding of two ways of creating objects by String
Introduction: as we all know, there are two ways to create string objects: String name1 = "jack"; String name2 = new String("jack");
1. String name1 = “jack”; Interpretation of
"jack" is a string constant, also known as a string literal, which is located in the string constant poolname1 is a stack variable that points to ...
Posted by twigletmac on Tue, 01 Feb 2022 12:59:45 +0100
[J2SE]Object. Implementation of hashcode
Contents of this article
1, Basic concepts2, Implementation of hotspot
Object.hashCode()
mark wordget_next_hash(thread, obj)System.identityHashCode(obj)3, Test verification
1. After GC, the memory address of the object changes, but the hash value remains unchanged2. The hash value is saved in the mark word of the object header
1, ...
Posted by insub2 on Wed, 19 Jan 2022 21:58:01 +0100
The equals() and hashcode() methods for object comparison in Java
equals() and hashcode() in Java object comparison
1. Comparison and analysis of equals() method and "= ="
First, put forward a misunderstanding:
==Address comparison during comparisonValues are compared when equals is compared
String a = "123";
String b = "123";
System.out.println(a.equals(b)); // true
System.out.println(a == b); ...
Posted by 28rain on Tue, 18 Jan 2022 22:33:57 +0100
How and why does Java override the equals and hashCode methods of objects
Foreword: if Java objects want to compare whether they are equal, they need to rewrite the equals method and the hashCode method, and the prime number 31 is used in the hashCode method. Let's see why.
1, Requirements:
Compare whether two objects are equal. For the following User object, it is considered the same object as long as the name a ...
Posted by Dave3765 on Sat, 15 Jan 2022 04:12:49 +0100