Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: wordsmithing

Arrays do not override the In Java, arrays are objects and support object methods such as Object.equals() method; the implementation of the equals() method compares . However, arrays do not support any methods besides those provided by Object. Consequently, using Object.equals() on any array only compares array references rather than their contents. Programmers who wish to compare the contents of two arrays must use the twothe static two-argument Arrays.equals() method.   Two arrays are considered equal  This method considers two arrays equivalent if both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equalequivalent, according to Object.equals().  In other words, two arrays are equal if they contain the same equivalent elements in the same order.  To  To test for reference equality, programmers can use the reference equality operators, == and !=.  To test for content equality, use Object.equals().

  Because the effect of using Object.equals() to compare two arrays is often misunderstoodmisconstrued as content equality, and because a better alternative exists in the use of reference equality operators, the use of the Object.equals() method to compare two arrays is disallowed by this rule.

Noncompliant Code Example

...