Arrays do not override the Object.equals()
method; rather, the implementation of the equals()
method compares array references rather than their contents. To compare the contents of two arrays, Programs must use the two-argument Arrays.equals()
method instead. When intentionally testing reference equality, to compare the contents of two arrays. Programs must use the reference equality operators, ==
and !=
. Inappropriate use , when intentionally testing reference equality. Use of the array equals()
method is forbidden, because it can lead to unexpected results. Consequently, programs must reserve use of the array equality operators == and != for testing whether two array references specifically refer to the same array object, and are required to use the two-argument Arrays. equals() method for all other cases.
This rule is a specialization of EXP01-J. Do not confuse abstract object equality with reference equality.
Noncompliant Code Example
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="949fa3dee2bc1af1-070512d5-45e94b74-84cd87eb-156d0d553cfa8e18f2dad796"><ac:plain-text-body><![CDATA[ | [[API 2006 | AA. Bibliography#API 06]] | [Class | http://download.oracle.com/javase/6/docs/api/java/util/Arrays.html] | ]]></ac:plain-text-body></ac:structured-macro> |
...