Search This Blog

Why does Java's hashCode() in String use 31 as a multiplier?

The hashcode for a String object is computed as
s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]


The question is why 31 is used? Answer is available at here

No comments:

Post a Comment