Java hashCode方法最大返回值

标签 java hash

谁能告诉我 Java String.hashCode() 方法可以返回的最大和最小 int 值是多少?

最佳答案

String.hashCode () 返回一个int,使用下面的公式计算:

public int hashCode()

Returns a hash code for this string.

The hash code for a String object is computed as

s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]

using int arithmetic, where s[i] is the i-th character of the string, n is the length of the string, and ^ indicates exponentiation. (The hash value of the empty string is zero.)


可以使用以下常量找到最小值和最大值。

 System.out.println (java.lang.Integer.MAX_VALUE); //  2147483647
 System.out.println (java.lang.Integer.MIN_VALUE); // -2147483648

关于Java hashCode方法最大返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11480009/

相关文章:

c -/net/ipmr.c中的MFC_HASH

perl - 如何在 Perl 中将这些字符串转换为哈希?

hash - 如何按出现的顺序获取哈希键

java - 带有 maven jetty 插件的 applcation.properties

Java 使用 Apache Spark 指定架构从 json 文件读取

java - 轻量化过程是什么意思?

javascript - 如果 v8 在对象增长时重新哈希

c# - 将 .Net 4.5.1 中的 KeyDerivation.Pbkdf2 转换为 .Net 4.0

java - JDO 架构 : One to many relationship and cascading deleting

java - 根据某些字段对对象进行分组