hashcode may be the same of different character strings

System.out.println("重地".hashCode()=="通话".hashCode());//结果为true

Return Value hashcode () method is an int, when the calculated hashcode beyond the scope of the int, hashcode accuracy can not be guaranteed, so that different character hashcode possible the same.

public static int hashCode(byte[] value) {
    int h = 0;
    for (byte v : value) {
        h = 31 * h + (v & 0xff);
    }
    return h;
}

Guess you like

Origin www.cnblogs.com/chenj-blog/p/12344704.html