It is often useful to look at the java code to see what is happening.
For example the String#hashCode
method
public int hashCode() {
int h = hash;
if (h == 0) {
int off = offset;
char val[] = value;
int len = count;
for (int i = 0; i < len; i++) {
h = 31*h + val[off++];
}
hash = h;
}
return h;
}
As you can see the result is based upon the value of the String, not its memory location.