Java.lang Package Classes

Java Float - hashCode() Method



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

Syntax

public static int hashCode(float value)

Parameters

value Specify the value to hash.

Return Value

Returns a hash code value for a float value.

Exception

NA.

Example:

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

import java.lang.*;

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

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

The output of the above code will be:

hashCode of the val1 is: 1092878336
hashCode of the val2 is: -1054605312

❮ Java.lang - Float