Java.lang.Character.hashCode()是Java中的內置方法,該方法返回此Character的哈希碼。返回的哈希碼等於調用charValue()的結果。
用法:
public int hashCode() This function does not accepts any parameter.
返回值:此方法返回此字符的哈希碼值。
以下程序說明了Java.lang.Character.hashCode()函數:
程序1:
// Java program to demonstrate the
// function when the value passed in the parameter
// is a character
import java.lang.*;
public class Gfg {
public static void main(String[] args)
{
// parameter ch
char ch = 'B';
// assigns character values
Character c = Character.valueOf(ch);
// assign hashcodes of c1, c2 to i1, i2
int i = c.hashCode();
// prints the character values
System.out.println("Hashcode of " + ch + " is " + i);
}
}
輸出:
Hashcode of B is 66
程序2:
// Java program to demonstrate the
// function when the value passed in the parameter
// is a number
import java.lang.*;
public class Gfg {
public static void main(String[] args)
{
// parameter ch
char ch = '6';
// assigns character values
Character c = Character.valueOf(ch);
// assign hashcodes of ch
int i = c.hashCode();
// prints the character values
System.out.println("Hashcode of " + ch + " is " + i);
}
}
輸出:
Hashcode of 6 is 54
相關用法
- Java Java lang.Long.lowestOneBit()用法及代碼示例
- Java Java lang.Long.numberOfTrailingZeros()用法及代碼示例
- Java Java lang.Long.highestOneBit()用法及代碼示例
- Java Java lang.Long.numberOfLeadingZeros()用法及代碼示例
- Java Java.util.Collections.rotate()用法及代碼示例
- Java Java.util.concurrent.Phaser用法及代碼示例
- Java Java.util.concurrent.RecursiveTask用法及代碼示例
- Java Java.util.function.BiPredicate用法及代碼示例
- Java Java lang.Long.reverse()用法及代碼示例
- Java Java lang.Long.builtcount()用法及代碼示例
- Java Java.util.function.IntPredicate用法及代碼示例
- Java Java.util.function.DoublePredicate用法及代碼示例
注:本文由純淨天空篩選整理自Twinkl Bajaj大神的英文原創作品 Character.hashCode() in Java with examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。