目录

static int hashCode(Object[] a)

描述 (Description)

java.util.Arrays.hashCode(Object[])方法根据指定数组的内容返回哈希码。 如果数组包含其他数组作为元素,则哈希代码基于它们的身份而不是它们的内容。对于任何两个数组a和b,例如Arrays.equals(a, b) ,它也是Arrays.hashCode(a) == Arrays.hashCode(b)

声明 (Declaration)

以下是java.util.Arrays.hashCode()方法的声明

public static int hashCode(Object[] a)

参数 (Parameters)

a - 这是要计算其哈希值的数组。

返回值 (Return Value)

此方法返回a的基于内容的哈希码。

异常 (Exception)

NA

例子 (Example)

以下示例显示了java.util.Arrays.hashCode()方法的用法。

package com.iowiki;
import java.util.Arrays;
public class ArrayDemo {
   public static void main(String[] args) {
      // initializing Object array
      Object[] ob = new Object[] { 22, 7 };
      // hashcode for value1
      int retval = ob.hashCode();
      // printing hash code value
      System.out.println("The hash code of value1 is: " + retval);
      // value2 for Object array
      ob = new Object[] { 3.5, 8.5 };
      // hashcode for value2
      retval = ob.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
↑回到顶部↑
WIKI教程 @2018