Java.lang Package Classes

Java Byte - hashCode() Method



The java.lang.Byte.hashCode() method returns a hash code for this Byte which is equal to the result of invoking intValue().

Syntax

public int hashCode()

Parameters

No parameter is required.

Return Value

Returns a hash code value for this Byte.

Exception

NA.

Example:

In the example below, the java.lang.Byte.hashCode() method returns a hash code for the given Byte.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating Byte objects
    Byte val1 = 25;
    Byte val2 = -25;

    //printing hashcode of the Byte objects
    System.out.println("hashCode of the val1 is: " + val1.hashCode()); 
    System.out.println("hashCode of the val2 is: " + val2.hashCode());   
  }
}

The output of the above code will be:

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

❮ Java.lang - Byte