44
I was just curious to know - why does Arrays.equals(double[][], double[][]) return false? when in fact the arrays have the same number of elements and each element is the same?
For example I performed the following test.
double[][] a, b;
int size =5;
a=new double[size][size];
b=new double[size][size];
for( int i = 0; i < size; i++ )
for( int j = 0; j < size; j++ ) {
a[i][j]=1.0;
b[i][j]=1.0;
}
if(Arrays.equals(a, b))
System.out.println("Equal");
else
System.out.println("Not-equal");
Returns false and prints "Not-equal".
on the other hand, if I have something like this:
double[] a, b;
int size =5;
a=new double[size];
b=new double[size];
for( int i = 0; i < size; i++ ){
a[i]=1.0;
b[i]=1.0;
}
if(Arrays.equals(a, b))
System.out.println("Equal");
else
System.out.println("Not-equal");
returns true and prints "Equal". Does the method only work with single dimensions? if so, is there something similar for multi-dimensional arrays in Java?