HashCode giving negative values

前端 未结 3 1755
离开以前
离开以前 2020-12-02 17:21

I am converting the incoming string into hash code by doing the following function but some of the values are negative. I don\'t think hash values should be negative. Please

3条回答
  •  隐瞒了意图╮
    2020-12-02 17:49

    sometimes the hashcode calculation itself goes beyond the Integer.MAX_VALUE, i.e 2147483647. what happens then is that we get a negative integer after the overflow. Negative hashcode is perfectly valid!

提交回复
热议问题