Facebook Page Twitter Page LinkedIn Page
× Java.lang Package Classes


The java.lang.Integer.hashCode() method is used to return a hash code for this Integer.

Syntax

public int hashCode()

Parameters

No parameter is required.

Return Value

Returns a hash code value for this object, equal to the primitive int value represented by this Integer object.

Exception

NA.

Example:

In the below example, the java.lang.Integer.hashCode() method is used to return a hash code for the given Integer.

import java.lang.*;

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

    //printing hashcode of the Integer 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 - Integer