Java 中 hashCode(int[] a) 方法有什麼作用?
java.util.Arrays 類中的 hashCode(int[]) 方法基於指定陣列的內容返回雜湊碼。對於任意兩個非 null int 陣列 a 和 b,只要 Arrays.equals(a, b),必定有 Arrays.hashCode(a) == Arrays.hashCode(b)。
示例
import java.util.Arrays;
public class ArrayDemo {
public static void main(String[] args) {
int[] ival = new int[] { 3, 5 };
int retval = ival.hashCode();
System.out.println("The hash code of value1 is: " + retval);
ival = new int[] { 19, 75 };
retval = ival.hashCode();
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
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP