hashCode(obj[] a) 方法在 Java 中做什么?
java.util.Arrays 类的 hashCode(Object[]) 方法基于指定数组的内容返回哈希码。如果数组包含其他元素数组,那么哈希码基于它们的标识,而不是它们的内容。对于任意两个数组 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) {
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