全屏
java.util.Arrays.hashCode(char[])方法返回基于指定数组的内容的哈希码。对于任何两个字符数组a和b,使得Arrays.equals(a,b),它也是类似情况Arrays.hashCode(a)== Arrays.hashCode(b)。
声明
以下是java.util.Arrays.hashCode()方法的声明public static int hashCode(char[] a)
参数a -- 这是用于计算哈希值的数组。
返回值
此方法返回一个基于内容的哈希码。
异常NA
例子
下面的示例演示java.util.Arrays.hashCode()方法的用法。package cn.sxt;
import java.util.Arrays;
public class ArrayDemo {
public static void main(String[] args) {
// initializing char array
char[] cval = new char[] { 'a', 'k' };
// hashcode for value1
int retval = cval.hashCode();
// printing hash code value
System.out.println("The hash code of value1 is: " + retval);
// value2 for char array
cval=new char[] { 'e', 'f', 'h' };
// hashcode for value2
retval=cval.hashCode();
// printing hash code value
System.out.println("The hash code of value2 is: " + retval);
}
}
让我们来编译和运行上面的程序,这将产生以下结果:The hash code of value1 is: 4072869
The hash code of value2 is: 1671711
分享到:
0评论