Comparing arrays

Arrays provides the overloaded method equals( ) to compare entire arrays for equality. Again, these are overloaded for all the primitives and for Object. To be equal, the arrays must have the same number of elements, and each element must be equivalent to each corresponding element in the other array, using the equals( ) for each element. (For primitives, that primitives wrapper class equals( ) is used; for example, Integer.equals( ) for int.)For example:

Originally, a1 and a2 are exactly equal, so the output is true, but then one of the elements is changed, which makes the result false. In the last case, all the elements of s1 point to the same object, but s2 has five unique objects. However, array equality is based on contents (via Object.equals( )) , so the result is true.