Can Java's hashCode produce same value for different strings?

前端 未结 12 875
情歌与酒
情歌与酒 2020-11-28 08:58

Is it possible to have same hashcode for different strings using java\'s hashcode function?or if it is possible then what is the % of its possibility?

12条回答
  •  青春惊慌失措
    2020-11-28 09:57

    YES. A lot.

    Look at following pair

    • "FB" and "Ea"

    can return same hash code even though the characters in it are not same.

    Basically it is the sum of characters in a string multiplied by an integer.

提交回复
热议问题