Java的hashCode可以为不同的字符串生成相同的值吗? [英] Can Java's hashCode produce same value for different strings?

查看:402
本文介绍了Java的hashCode可以为不同的字符串生成相同的值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用java的哈希码函数为不同的字符串使用相同的哈希码?或者如果可能的话,它的可能性百分比是多少?

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?

推荐答案

Java哈希码是32位。它散列的可能字符串数量是无限的。

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.

这篇关于Java的hashCode可以为不同的字符串生成相同的值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆