From the link below, I know Java uses (hash & 0x7FFFFFFF) % tab.length
to decide which slot of an array to put the {key, value} in.
My question is why Java first does hash & 0x7FFFFFFF? Is there any particular purpose?
Because:
0x7FFFFFFF
is 0111 1111 1111 1111 1111 1111 1111 1111 : all 1 except the sign bit.
(hash & 0x7FFFFFFF)
will result in a positive integer.
(hash & 0x7FFFFFFF) % tab.length
will be in the range of the tab length.