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

前端 未结 12 854
情歌与酒
情歌与酒 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:43

    A Java hash code is 32bits. The number of possible strings it hashes is infinite.

    So yes, there will be collisions. The percentage is meaningless - there is an infinite number of items (strings) and a finite number of possible hashes.

提交回复
热议问题