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

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.