or, in code,

int h = 0; for (int i = 0; i < n; i++) { h = 31*h + s.charAt(i); }For example the hash code of

to give the value

hello

In general the arithmetic operations in such expressions will use 32-bit modular arithmetic

where`Integer.MAX_VALUE + 1`

=`Integer.MIN_VALUE`

Note that, because of wraparound associated with modular arithmetic, the hash code could be negative, or even zero. It happened to be positive in this case because

`Integer.MAX_VALUE`

= `Integer.MIN_VALUE`

=