I was playing around with hash codes and I noticed that some hash codes for a String object is negative. While not a revelation in itself, I'm curious about the mechanism that causes it. The javadoc states that the hashcode is computed via the algorithm
s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
As far as I can tell, this shouldn't yield a negative number. Is some kind of wrapping around taking place?
Thoughts? comments?