在 Java 中,hashCode(int[] a) 方法做什么?
java.util.Arrays 类中的 hashCode(int[]) 方法基于指定数组的内容返回哈希码。对于任何两个非空 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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP