Java Short.hashCode() example

Java Short.hashCode() example

By Yashwant Chavan, Views 13, Date 24-Apr-2018

In this java tutorial, You will learn how to use hashCode() method of Short class. This method is use to returns a hash code for this Short; equal to the result of invoking intValue(). This method returns a hash code value for this Short.

tags Java

Returns a hash code for this Short.

Syntax

public int hashCode()

Returns

A hash code value for this Short.

Java Short hashCode() example

  • Assign two short values.
  • Create an instance of short values e.g new Short(value);
  • firstValue.hashCode();It will return the hash code value for firstValue.
  • secondValue.hashCode();It will return the hash code value for secondValue.
  • Print the hash code values.
package com.technicalkeeda;

public class App {

    public static void main(String[] args) {

        short value1 = 50;
        Short firstValue = new Short(value1);

        short value2 = -20;
        Short secondValue = new Short(value2);

        int result1 = firstValue.hashCode();
        int result2 = secondValue.hashCode();

        System.out.println("The hash code value for firstValue :- " + result1);
        System.out.println("The hash code value for secondValue :- " + result2);
    }
}

output

The hash code value for firstValue :- 50
The hash code value for secondValue :- -20

Suggested Posts

Yashwant

Yashwant

Hi there! I am founder of technicalkeeda.com and programming enthusiast. My skills includes Java,J2EE, Spring Framework, Nodejs, PHP and lot more. If you have any idea that you would want me to develop? Lets connect: yashwantchavan[at][gmail.com]