Java Double hashCode()方法及示例
Double类的 hashCode() 方法是一个内置方法,用于返回该Double对象的哈希码值。
语法
DoubleObject.hashCode()
参数: 它不需要任何参数。
返回类型: 它返回一个 int 值。返回的值是 (int)(v^(v >>32)) **,其中v是一个长变量,等于 **Double.doubleToLongBits(this.doubleValue() )。
下面是hashCode()方法的实现。
例1 :
// Java code to demonstrate// Double hashCode() Method class GFG { public static void main(String[] args) { double d = 118.698; // creating Double object. Double value = new Double(d); // hashCode() method Double class int output = value.hashCode(); // printing the output System.out.println("Hashcode Value of " + value + " : " + output); }}
输出。
Hashcode Value of 118.698 : 1215072837
例2 :
// Java code to demonstrate// Double hashCode() Method class GFG { public static void main(String[] args) { int i = -30; // creating Double object. Double value = new Double(i); // hashCode() method Double class int output = value.hashCode(); // printing the output System.out.println("Hashcode Value of " + value + " : " + output); }}
输出。
Hashcode Value of -30.0 : -1069678592
