Java.util.Arrays.hashCode(byte [])


描述

所述java.util.Arrays.hashCode(byte[])方法返回基于指定数组的内容的散列码。对于任何两个字节的数组a和b,使得Arrays.equals(a,b),Arrays.hashCode(a)== Arrays.hashCode(b)的情况也是如此。

声明

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

public static int hashCode(byte[] a)

参数

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

返回值

该方法返回一个基于内容的哈希码一个。

异常

NA

实例

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

package com.tutorialspoint;

import java.util.Arrays;

public class ArrayDemo {
   public static void main(String[] args) {

      // initializing byte array
      byte[] bval = new byte[] { 10, 45 };

      // hashcode for value1
      int retval = bval.hashCode();

      // printing hash code value
      System.out.println("The hash code of value1 is: " + retval);

      // value2 for byte array
      bval = new byte[] { 25, 35, 67 };

      // hashcode for value2
      retval = bval.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