Close

Java Collections - Arrays.deepHashCode() Examples

Java Collections Java Java API 


Class:

java.util.Arrays

java.lang.Objectjava.lang.Objectjava.util.Arraysjava.util.ArraysLogicBig

Method:

public static int deepHashCode(Object[] a)

This method returns a hash code based on the "deep contents" of the specified array. If the array contains other arrays as elements, the hash code is based on their contents and so on.


Examples


package com.logicbig.example.arrays;

import java.util.Arrays;

public class DeepHashCodeExample {

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
1530317374
2047377234




See Also