Java.lang.Byte 类

java.lang.Byte.hashCode() 方法返回此 Byte 的哈希码,该哈希码等于以下结果调用 intValue()。

语法

public int hashCode()

参数

无需参数。

返回值

返回此字节的哈希码值。

异常

无。

示例:

In在下面的示例中,java.lang.Byte.hashCode() 方法返回给定 Byte 的哈希代码。

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //创建Byte对象
    Byte val1 = 25;
    Byte val2 = -25;

    //打印Byte对象的哈希码
    System.out.println("hashCode of the val1 is: " + val1.hashCode()); 
    System.out.println("hashCode of the val2 is: " + val2.hashCode());   
  }
}

上述代码的输出将是:

hashCode of the val1 is: 25
hashCode of the val2 is: -25