java中的hashCode(obj[] a)方法有什麼作用?
java.util.Arrays 類的 hashCode(Object[]) 方法基於指定陣列的內容返回一個雜湊碼。如果該陣列包含其他元素陣列,那麼雜湊碼是基於它們的身份而不是內容。對於任何兩個陣列 a 和 b,使得 Arrays.equals(a, b) 為 true,那麼 Arrays.hashCode(a) == Arrays.hashCode(b) 也為 true。
示例
import java.util.Arrays;
public class ArrayDemo {
public static void main(String[] args) {
Object[] ob = new Object[] { 22, 7 };
int retval = ob.hashCode();
System.out.println("The hash code of value1 is: " + retval);
ob = new Object[] { 3.5, 8.5 };
retval = ob.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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言教程
C++
C#
MongoDB
MySQL
Javascript
PHP