当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java Java.util.Arrays.hashCode(short[])用法及代码示例



描述

这个java.util.Arrays.hashCode(short[])方法根据指定数组的内容返回一个哈希码。对于任何两个短数组 a 和 b 使得 Arrays.equals(a, b),Arrays.hashCode(a) == Arrays.hashCode(b) 也是这种情况。

声明

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

public static int hashCode(short[] 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 short array
      short[] sval = new short[] { 2 };

      // hashcode for value1
      int retval = sval.hashCode();
      
      // printing hash code value
      System.out.println("The hash code of value1 is:" + retval);
      
      // value2 for short array
      sval = new short[] { 30, 50 };

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

相关用法


注:本文由纯净天空筛选整理自 Java.util.Arrays.hashCode(short[]) Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。