http://www.javashuo.com/article/p-ridzetqx-gh.htmlhtml
/** *String 的 char 數組的數字每次乘以 31 再疊加最後返回,所以,每一個不一樣的字符串,返回的 hashCode 確定不同 */ public int hashCode() { int h = hash; if (h == 0 && value.length > 0) { char val[] = value; for (int i = 0; i < value.length; i++) { h = 31 * h + val[i]; } hash = h; } return h; }
static final int hash(Object key) { int h; return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16); }