Java-util-arrays-hashcode-short

提供:Dev Guides
移動先:案内検索

Java.util.Arrays.hashCode(short [])メソッド

説明

  • java.util.Arrays.hashCode(short [])*メソッドは、指定された配列の内容に基づいてハッシュコードを返します。 _Arrays.equals(a、b)_であるような2つの短い配列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.finddevguides;

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