Home » Java Float hashCode() method with Examples

Java Float hashCode() method with Examples

by Online Tutorials Library

Java Float hashCode() method

The hashCode() method of Java Float class returns the hash code for this Float. The result is represented as integer bit representation whose value is same as produced by the floatToIntBits(float) method. The hashCode() method of Float class overrides the hashCode() method of class Object.

Syntax:

Parameters:

  • NA
  • The value provided to hash.

Return Value:

This method returns a hash code value for this float object.

Example 1

Test it Now

Output:

1. Hash Value = 0    2. Hash Value = 1143586816    3. Hash Value = 1143586818    4. Hash Value = -1003896832  

Example 2

Test it Now

Output:

Enter your admission No  1197  Your id is : 1150656512    Enter your admission No  1198  Your id is : 1150664704  

Example 3

Test it Now

Output:

HAsh code value = 1119617024  Float value  = 1119617024  

Example 4

Test it Now

Output:

Error:(11, 30) java: incompatible types: int cannot be converted to java.lang.Float  

Note: Here with hashCode() method, we are converting the object into int bits and without any explicit cast, we are putting it into Float, so it is giving us an error. Either we should typecast it or should directly call this method in println function.

Next TopicJava Float

You may also like