ayush raj wrote:I tried for Integer , Float .. but they are showing me output as the value and not the hashCode value . I wrote :
Why is it so ? Why do we require hashing in such cases ?
Henry Wong:
I disagree with this
ayush raj wrote:I tried for Integer , Float .. but they are showing me output as the value and not the hashCode value . I wrote :
Why is it so ? Why do we require hashing in such cases ?
/**
* Returns a hash code for this string. The hash code for a
* <code>String</code> object is computed as
* <blockquote><pre>
* s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
* </pre></blockquote>
* using <code>int</code> arithmetic, where <code>s[i]</code> is the
* <i>i</i>th character of the string, <code>n</code> is the length of
* the string, and <code>^</code> indicates exponentiation.
* (The hash value of the empty string is zero.)
*
* @return a hash code value for this object.
*/
public int hashCode() {
int h = hash;
int len = count;
if (h == 0 && len > 0) {
int off = offset;
char val[] = value;
for (int i = 0; i < len; i++) {
h = 31*h + val[off++];
}
hash = h;
}
return h;
}
ayush raj wrote:
Henry Wong:
I disagree with this
I don't know what you disagree with , but this output:- 10 10 , is being displayed by my JVM .
If I'd had more time, I would have written a shorter letter. -T.S. Eliot such a short, tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|