相关疑难解决方法(0)

使用hashCode()测试字符串相等性

是否有任何理由不能使用hashCode方法测试Java字符串的相等性?所以基本上,而不是....

"hello".equals("hello")
Run Code Online (Sandbox Code Playgroud)

你可以用......

"hello".hashCode() == "hello".hashCode()
Run Code Online (Sandbox Code Playgroud)

这很有用,因为一旦字符串计算了它的哈希码,那么比较一个字符串就像比较一个int一样有效,因为字符串缓存了哈希码,而且很可能字符串在字符串池中,如果你设计它办法.

java string hashcode

22
推荐指数
4
解决办法
2万
查看次数

标签 统计

hashcode ×1

java ×1

string ×1