Skip to content

Commit aa7296c

Browse files
committed
Hash Code Formula
Signed-off-by: https://github.com/Someshdiwan <[email protected]>
1 parent 67708e9 commit aa7296c

File tree

1 file changed

+47
-0
lines changed
  • Section 25 Collections Frameworks/Map Interface/HashMap/src/HashCode

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"ABC" string ka hashCode step-by-step ASCII flow bana dete hain.
2+
3+
Yeh Java ka String.hashCode() ka actual formula hai:
4+
5+
h = 31*h + char
6+
7+
8+
9+
Example: "ABC"
10+
11+
Initial:
12+
h = 0
13+
14+
Step 1: 'A' = 65
15+
h = 31*0 + 65 = 65
16+
17+
Step 2: 'B' = 66
18+
h = 31*65 + 66
19+
= 2015 + 66
20+
= 2081
21+
22+
Step 3: 'C' = 67
23+
h = 31*2081 + 67
24+
= 64511 + 67
25+
= 64578
26+
27+
28+
29+
ASCII Flow Diagram
30+
31+
String = "ABC"
32+
33+
h = 0
34+
35+
├── 'A' (65) → h = 31*0 + 65 = 65
36+
37+
├── 'B' (66) → h = 31*65 + 66 = 2081
38+
39+
└── 'C' (67) → h = 31*2081 + 67 = 64578
40+
41+
Final hashCode("ABC") = 64578
42+
43+
44+
45+
Isliye "ABC".hashCode() = 64578 Java me.
46+
47+

0 commit comments

Comments
 (0)