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