1 Public classTest {2 Public Static voidMain (string[] args) {3 int[] A = {1, 2, 4, 6};4 int[] B =A;5 int[] C = {1, 2, 4, 6};6 7 //The following method prints a reference address for an array of a8 System.out.println (a.tostring ());9 //The following method compares the two-array reference for equalityTenSystem.out.println ("A.equals (b):" +A.equals (b)); One //The following method is the real tostring method of the A array A System.out.println (Arrays.tostring (a)); - //The following method is the true Equals method of the array -System.out.println ("Arrays.equals (a,c):" +Arrays.equals (A, c)); the } -}
Summary: The Java array does not override the ToString method and the Equals method, and when we call these two methods of a Java object directly, the two methods in the Java.lang.Object class are actually called.
To implement the array class itself, these two operations must pass the ToString () method of the Java.util.Arrays class and the two static methods of Equals (A, B).
Note: The ToString method of the Java.lang.Object class prints out the reference address of the object, and the Equals () method compares the reference to two objects by default.
The ToString method and the Equals method of the Java array and the ToString method of the Java.lang.Object object and the Equals method