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

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

    The percentage of collisions for random strings should be minimal. However, if you hash strings from external sources, an attacker could easily create hundreds of thousands of strings having the same hashcode. In a java HashMap these would all map to the same bucket and effectively turn the map into a linked list. Access times to the map would then be proportional to the map size instead of constant, leading to a denial of service attack.

    See this page on Effective DoS attacks against Web Application Plattforms for further information links to the presentation.

提交回复
热议问题