Java's ToString () method

Source: Internet
Author: User
Tags expression hash integer tostring

Java Foundation Content

The ToString method We use everywhere, is a very important little knowledge, here about:

We look at the API documentation to see a detailed description of the Java.lang.Object class's ToString Method:

Tostring

Public String toString ()

Returns a string representation the object. In general, the ToString method is returns a string that "textually represents" this object. The result should being a concise but informative representation that are easy for a person to read. It is recommended the all subclasses override this method.

The ToString method for class Object returns a string consisting of the name of the class of which the Object being an Instan CE, the at-sign character ' @ ', and the unsigned hexadecimal representation of the hash code of the object. In the other words, this is returns a string equal to the value of:

GetClass (). GetName () + ' @ ' + integer.tohexstring (hashcode ())

Returns:

A string representation the object.

We probably translate:

Returns a string that can represent this object. In general, the ToString method returns the "text expression" of this object. The return result is concise but not an informative expression that is easy for people to read. It is recommended that you override this method when using subclasses.

For the class object, the ToString method return value is made up of the class name of the owning class, an "@" symbol, and an unsigned hexadecimal expression of the object's hash code. In other words, the string returned by this method is equivalent to the value returned by the following method:

GetClass (). GetName () + ' @ ' + integer.tohexstring (hashcode ())

Return:

The string expression of this object

Let's look at the ToString method in the Java.lang.String class to see if it's the same.

Tostring

Public String toString ()

This object (which are already a string!) is itself returned.

Specified by:

ToString in Interface charsequence

Overrides:

ToString in class Object

Returns:

The string itself.

Let's just translate it:

The object itself (which is already a string) is the return value

Description

The ToString method in the Charsequence interface

Rewrite:

To rewrite the ToString method in object

Return:

string of its own

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.