gpt4 book ai didi

java - 将 "asdfgh"等字符串转换为整数值

转载 作者:行者123 更新时间:2023-12-01 19:03:59 25 4
gpt4 key购买 nike

我想将字符串转换为“asdfgh”而不是“2345”,我知道我们可以使用以下方法转换“2345”: Integer.parseInt("stringOfNumber");但我必须将“asdfgg”转换为java中的整数值。

请帮助我。

提前致谢。

最佳答案

使用方法hashCode ,这将根据文档返回任何字符串的 int 值。

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 ith character of the string, n is the length of the string, and ^ indicates exponentiation. (The hash value of the empty string is zero.)

关于java - 将 "asdfgh"等字符串转换为整数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10984832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com