本文整理了Java中java.lang.String.hashCode()
方法的一些代码示例,展示了String.hashCode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。String.hashCode()
方法的具体详情如下:
包路径:java.lang.String
类名称:String
方法名: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 ith character of the string, n
is the length of the string, and ^
indicates exponentiation. (The hash value of the empty string is zero.)
[中]返回此字符串的哈希代码。String
对象的哈希代码使用int
算法计算为
s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
,其中s[i]
是字符串的第i个字符,n
是字符串的长度,^
表示幂运算。(空字符串的哈希值为零。)
代码示例来源:origin: google/guava
@Override
public int hashCode() {
return name.hashCode();
}
}
代码示例来源:origin: google/guava
@Override
public int hashCode() {
return justAfterNull.hashCode();
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public int hashCode() {
int result = this.beanName.hashCode();
result = 29 * result + (this.toParent ? 1 : 0);
return result;
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public int hashCode() {
int result = 27;
for (String pattern : this.patterns) {
result = 13 * result + pattern.hashCode();
}
for (String excludedPattern : this.excludedPatterns) {
result = 13 * result + excludedPattern.hashCode();
}
return result;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* This implementation returns the hash code of the underlying description String.
*/
@Override
public int hashCode() {
return this.description.hashCode();
}
代码示例来源:origin: spring-projects/spring-framework
/**
* This implementation returns the hash code of the underlying
* class path location.
*/
@Override
public int hashCode() {
return this.path.hashCode();
}
代码示例来源:origin: stackoverflow.com
final TelephonyManager tm = (TelephonyManager) getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);
final String tmDevice, tmSerial, androidId;
tmDevice = "" + tm.getDeviceId();
tmSerial = "" + tm.getSimSerialNumber();
androidId = "" + android.provider.Settings.Secure.getString(getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
UUID deviceUuid = new UUID(androidId.hashCode(), ((long)tmDevice.hashCode() << 32) | tmSerial.hashCode());
String deviceId = deviceUuid.toString();
代码示例来源:origin: square/okhttp
@Override public int hashCode() {
int result = 29;
result = 31 * result + scheme.hashCode();
result = 31 * result + authParams.hashCode();
return result;
}
代码示例来源:origin: square/okhttp
@Override public int hashCode() {
int result = 17;
result = 31 * result + pattern.hashCode();
result = 31 * result + hashAlgorithm.hashCode();
result = 31 * result + hash.hashCode();
return result;
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public int hashCode() {
return name.hashCode()
^ Integer.rotateLeft(descriptor.hashCode(), 8)
^ Integer.rotateLeft(bootstrapMethod.hashCode(), 16)
^ Integer.rotateLeft(Arrays.hashCode(bootstrapMethodArguments), 24);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* This implementation returns {@code toString()}'s hash code.
* @see #toString()
*/
@Override
public int hashCode() {
return toString().hashCode();
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public int hashCode() {
int hashCode = this.beanDefinition.hashCode();
hashCode = 29 * hashCode + this.beanName.hashCode();
hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(this.aliases);
return hashCode;
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public int hashCode() {
int result = this.foo.hashCode();
result = 31 * result + this.bar.hashCode();
return result;
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Generate a unique hash code for all properties of this
* {@code WebMergedContextConfiguration} excluding the
* {@linkplain #getTestClass() test class}.
*/
@Override
public int hashCode() {
return super.hashCode() * 31 + this.resourceBasePath.hashCode();
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public Integer apply(Integer t1) {
// be slow ... but faster than Thread.sleep(1)
String t = "";
int s = sink;
for (int i = 2000; i >= 0; i--) {
t = String.valueOf(i + t.hashCode() + s);
}
sink = t.hashCode();
return t1;
}
代码示例来源:origin: google/guava
@Override
public int hashCode() {
onHashCode.run();
return delegateString.hashCode();
}
代码示例来源:origin: google/guava
@Override
public int hashCode() {
onHashCode.run();
return delegateString.hashCode();
}
代码示例来源:origin: google/guava
@Override
public int hashCode() {
onHashCode.run();
return delegateString.hashCode();
}
代码示例来源:origin: google/guava
@Override
public int hashCode() {
onHashCode.run();
return delegateString.hashCode();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void nullSafeHashCodeWithObjectArray() {
int expected = 31 * 7 + "Leia".hashCode();
expected = 31 * expected + "Han".hashCode();
Object[] array = {"Leia", "Han"};
int actual = ObjectUtils.nullSafeHashCode(array);
assertEquals(expected, actual);
}
内容来源于网络,如有侵权,请联系作者删除!