equalson an array, which is equivalent to
This method invokes the
.equals(Object o) method on an array. Since arrays do not override the
equals method of
equals on an array is the same as comparing their addresses.
To compare the contents of the arrays, use
java.util.Arrays.equals(Object, Object). To compare the addresses of the arrays, it would be less confusing to explicitly check pointer equality using
String a = new String(); String b = new String(); // a and b are populated with the same data. assertTrue(a.equals(b)); // Fails, address of a not equal to address of b. // Or assertTrue(a == b); // Fails for the same reason.
assertTrue(Arrays.equals(a, b)); // Compares contents of a and b.