Float hashCode()方法在Java中的应用与实例
Float类中的 hashCode() 方法是Java中的一个内置方法,用于返回该Float对象的哈希码值。
语法
public int hashCode()
参数: 它不需要任何参数。
返回: 该函数为该对象返回一个哈希代码值。
下面是hashCode()方法的实现。
例1 :
// Java code to demonstrate// Float hashCode() Method class GFG { public static void main(String[] args) { float d = 118.698f; // creating Float object. Float value = new Float(d); // hashCode() method Float class int output = value.hashCode(); // printing the output System.out.println("Hashcode Value of " + value + " : " + output); }}
输出。
Hashcode Value of 118.698 : 1122854240
例2 :
// Java code to demonstrate// Float hashCode() Method class GFG { public static void main(String[] args) { int i = -30; // creating Float object. Float value = new Float(i); // hashCode() method Float class int output = value.hashCode(); // printing the output System.out.println("Hashcode Value of " + value + " : " + output); }}
输出。
Hashcode Value of -30.0 : -1041235968
