Saturday, November 22, 2025
HomeLanguagesJavaShort hashCode() method in Java with Examples

Short hashCode() method in Java with Examples

The hashCode() method of Short class is a built in method in Java which is used to return the hash code of the ShortObject.

Note: The hashCode() returns the same value as intValue().

Syntax

ShortObject.hashCode()

Return Value: It return an int value which represents the hashcode of the specified Short object.

Below is the implementation of hashCode() method in Java:

Example 1:




// Java code to demonstrate
// Short hashCode() method
  
class GFG {
    public static void main(String[] args)
    {
  
        String value = "74";
  
        // wrapping the short value
        // in the wrapper class Short
        Short b = new Short(value);
  
        // hashCode of the Short Object
        int output = b.hashCode();
  
        // printing the output
        System.out.println("HashCode of "
                           + b + " : " + output);
    }
}


Output:

HashCode of 74 : 74

Example 2:




// Java code to demonstrate
// Short hashCode() method
  
class GFG {
    public static void main(String[] args)
    {
  
        String value = "-17";
  
        // wrapping the short value
        // in the wrapper class Short
        Short b = new Short(value);
  
        // hashCode of the Short Object
        int output = b.hashCode();
  
        // printing the output
        System.out.println("HashCode of "
                           + b + " : " + output);
    }
}


Output:

HashCode of -17 : -17
RELATED ARTICLES

Most Popular

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6784 POSTS0 COMMENTS
Nicole Veronica
11931 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11999 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6863 POSTS0 COMMENTS
Umr Jansen
6848 POSTS0 COMMENTS