java.util.Arrays.hashCode(char[])%uA0方法返回基于指定数组的内容的哈希码。对于任何两个字符数组a和b,使得Arrays.equals(a,b),它也是类似情况Arrays.hashCode(a)== Arrays.hashCode(b)。
声明
以下是java.util.Arrays.hashCode()方法的声明
public static int hashCode(char[] a)
参数
-
a%uA0-- 这是用于计算哈希值的数组。
返回值
此方法返回一个基于内容的哈希码。
异常
- NA
例子
下面的示例演示java.util.Arrays.hashCode()方法的用法。
package com.yiibai import java.util.Arrays public class ArrayDemo { public static void main(String[] args) { // initializing char array char[] cval = new char[] { &aposa&apos, &aposk&apos } // 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[] { &apose&apos, &aposf&apos, &aposh&apos } // 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