java - Method deepHashCode of Arrays class on two dimensional array -


i have problems understanding behavior of arrays.deephashcode on int[][]. assume program easy enough read. , b has equal hash expected. d different rest. reason c equal , b. c transpose of arraya (and arrayb), may coincidence , not reason same hash code returned.

am not supposed use method on int[][]? suggestions of way make own hashcode int[][] returns equal integer if , if each element in each subarray equal each other (same position, same length...like deep cloned)

import java.util.arrays; public class test{     public static void main(string[] args){              int[][] arraya = new int[][]{                 {1,2,3},                 {4,5,6},                 {7,8,9}             };              int[][] arrayb = new int[][]{                 {1,2,3},                 {4,5,6},                 {7,8,9}             };              int[][] arrayc = new int[][]{                 {1,4,7},                 {2,5,8},                 {3,6,9}             };              int[][] arrayd = new int[][]{                 {1,5,9},                 {2,3,7},                 {4,6,8}             };              system.out.println("deep hash codes:");             system.out.println("array a: " + arrays.deephashcode(arraya));             system.out.println("array b: " + arrays.deephashcode(arrayb));             system.out.println("array c: " + arrays.deephashcode(arrayc));             system.out.println("array d: " + arrays.deephashcode(arrayd));     } } 

output:

deep hash codes:  array a: 30729379  array b: 30729379  array c: 30729379  array d: 30760099 

any suggestions of way make own hashcode int[][] returns equal integer if , if each element in each subarray equal each other (same position, same length...like deep cloned)

that impossible.

there many different integers. array of integers has lot more combinations. there collisions.

all hashcode can guarantee opposite: if 2 arrays have different hashcode, different.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -