+ 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()); } }
1 Answer
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