These methods return a hash code based on the contents of the specified array.
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);
}
}
Output
68612
852797571
1319456297