0
Hi, can anyone please tell me that why new object of String class hashcode returns 0 as output.
Is it because no object is created? String s = new String(); System.out.println(s.hashcode()); Output is 0.
1 Respuesta
+ 2
The hash code for a String object is computed as :
s[0]*31^(n - 1) + s[1]*31^(n - 2) + ... + s[n - 1]
For empty string value of "n" is zero hence hash code value is also zero