I was reading the code for the Arrays.hashCode
provided below,
public static int hashCode(Object a[]) {
if (a == null)
return 0;
int result = 1;
for (Object element : a)
result = 31 * result + (element == null ? 0 : element.hashCode());
return result;
}
I find it's not as clear as for why 31
is chosen for the hashing.
Secondly, the element.hashCode()
send me to the Object
class that defines it:
@HotSpotIntrinsicCandidate
public native int hashCode();
How the element.hashCode()
is calculaed for the each iteration?
Thank you.