Java-util-arrays-hashcode-int
提供:Dev Guides
Java.util.Arrays.hashCode(int [])メソッド
説明
- java.util.Arrays.hashCode(int [])*メソッドは、指定された配列の内容に基づいてハッシュコードを返します。 _Arrays.equals(a、b)_であるような2つの非null int配列aおよびbの場合、_Arrays.hashCode(a)== Arrays.hashCode(b)_でもあります。
宣言
以下は* java.util.Arrays.hashCode()*メソッドの宣言です
public static int hashCode(int[] 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 int array
int[] ival = new int[] { 3, 5 };
//hashcode for value1
int retval = ival.hashCode();
//printing hash code value
System.out.println("The hash code of value1 is: " + retval);
//value2 for double array
ival = new int[] { 19, 75 };
//hashcode for value2
retval = ival.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