Java.lang Package Classes

Java Float - hashCode() Method



The java.lang.Float.hashCode() method returns a hash code for this Float object. The result is the integer bit representation, exactly as produced by the method floatToIntBits(float), of the primitive float value represented by this Float object.

Syntax

public int hashCode()

Parameters

No parameter is required.

Return Value

Returns a hash code value for this object.

Exception

NA.

Example:

In the example below, the java.lang.Float.hashCode() method returns a hash code for the given float object.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating Float objects
    Float val1 = 10.25f;
    Float val2 = -10.25f;

    //printing hashcode of the Float 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: 1092878336
hashCode of the val2 is: -1054605312

❮ Java.lang - Float