Java.lang Package Classes

Java Short - hashCode() Method



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

Syntax

public static int hashCode(short value)

Parameters

value Specify the value to hash.

Return Value

Returns a hash code value for a short value.

Exception

NA.

Example:

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

import java.lang.*;

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

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

The output of the above code will be:

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

❮ Java.lang - Short