Why is the following code printing "Different."?
boolean[][] a = { {false,true}, {true,false} };
boolean[][] b = { {false,true}, {true,false} };
if (Arrays.equals(a, b) || a == b)
System.out.println("Equal.");
else
System.out.println("Different.");
Because
Arrays.equalsperforms a shallow comparison. Since arrays inherit theirequals-method fromObject, an identity comparison will be performed for the inner arrays, which will fail, sinceaandbdo not refer to the same arrays.If you change to
Arrays.deepEqualsit will print"Equal."as expected.