Java Collections Java Java API
java.util.Arrays
These methods return a hash code based on the contents of the specified array.
public static int hashCode(long[] a)
public static int hashCode(int[] a)
public static int hashCode(short[] a)
public static int hashCode(char[] a)
public static int hashCode(byte[] a)
public static int hashCode(boolean[] a)
public static int hashCode(float[] a)
public static int hashCode(double[] a)
public static int hashCode(Object[] a)
package com.logicbig.example.arrays;import java.util.Arrays;public class HashCodeExample { public static void main(String... args) { int[] arr1 = {3, 5, 6, 7, 9}; //native int h1 = arr1.hashCode(); //individual direct elements#hashCode, if element is array then native int h2 = Arrays.hashCode(arr1); System.out.println(h1); System.out.println(h2); }}
56209007831554661
For nested arrays we should use Arrays#deepHashcode()
package com.logicbig.example.arrays;import java.util.Arrays;public class HashCodeExample2 { public static void main(String... args) { Object[] arr1 = {3, 5, new int[]{6, 7, 9}}; //native int h3 = arr1.hashCode(); //individual direct elements#hashCode, if element is array then native int h2 = Arrays.hashCode(arr1); //deep, recursive elements#hashcode int h1 = Arrays.deepHashCode(arr1); System.out.println(h1); System.out.println(h2); System.out.println(h3); }}
68612173963223052426758