+ 1

Why same of both hashCode is same where both object creation is diffrent in string?

class Program { public static void main(String[] args) { String a1= new String("Literal"); String a2 = "Literal"; System.out.println(a1.hashCode()); System.out.println(a2.hashCode()); } }

30th Jul 2018, 7:13 PM
Ibney Ali
Ibney Ali - avatar
1 Respuesta
0
It doesn't matter how they are created. Those are two equal strings. When two objects are equal then they have the same hashCode
30th Jul 2018, 7:29 PM
Lstiti