Avoid using equals() to compare Java arrays by content: arrays inherit Object.equals(), which compares identity like == rather than elements. section 7.2
Compare array contents explicitly
int[] first = {1, 2, 3}; int[] second = {1, 2, 3}; first.equals(second); // false Arrays.equals(first, second); // true Arrays.deepEquals(matrix1, matrix2); // nested arrays section 7.2
Choose the comparison deliberately:
- Use Arrays.equals() for ordinary arrays and Arrays.deepEquals() for nested arrays. section 7.2
- Do not generalize equals() as a reliable content comparison; several JDK types also retain identity-style behavior. section 7.2
