Java.util.Arrays.hashCode(float[]) 方法
描述
java.util.Arrays.hashCode(float[]) 方法根据指定数组的内容返回一个哈希码。 对于满足 Arrays.equals(a, b) 的任意两个浮点数组 a 和 b,Arrays.hashCode(a) == Arrays.hashCode(b)。
声明
以下是 java.util.Arrays.hashCode() 方法的声明
public static int hashCode(float[] a)
参数
a − 这是要计算其哈希值的数组。
返回值
此方法返回 a 的基于内容的哈希码。
异常
NA
示例
下面的例子展示了 java.util.Arrays.hashCode() 方法的使用。
package com.tutorialspoint;
import java.util.Arrays;
public class ArrayDemo {
public static void main(String[] args) {
// initializing float array
float[] fval = new float[] { 32.1f, 55.4f };
// hashcode for value1
int retval = fval.hashCode();
// printing hash code value
System.out.println("The hash code of value1 is: " + retval);
// value2 for double array
fval = new float[] { 11.2f, 78.4f };
// hashcode for value2
retval = fval.hashCode();
// printing hash code value
System.out.println("The hash code of value2 is: " + retval);
}
}
让我们编译并运行上面的程序,这将产生以下结果 −
The hash code of value1 is: 4072869 The hash code of value2 is: 1671711

