Java.lang Package Classes

Java Byte - hashCode() Method



The java.lang.Byte.hashCode() method returns a hash code for a byte value which is compatible with Byte.hashCode().

Syntax

public static int hashCode(byte value)

Parameters

value Specify the value to hash.

Return Value

Returns a hash code value for a byte value.

Exception

NA.

Example:

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

import java.lang.*;

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

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

The output of the above code will be:

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

❮ Java.lang - Byte