2015-09-11 Issue (II)

Source: Internet
Author: User

1.Integer a=new Integer (6);//????
System.out.println (a);//The value of the output is still 6???

(1) Each object has an (inherited or re-) toString () method, which is typically used to output some information related to the object. The ToString () method of the integer is as follows:

1  /**2 * Returns a {@codeString} object representing this3      * {@codeInteger} ' s value. The value is converted to signed4 * Decimal representation and returned as a string, exactly as if5 * The integer value were given as a argument to the {@link6 * java.lang.integer#tostring (int)} method.7      *8      * @returna string representation of the value of this object in9 * base 10.Ten      */ One      PublicString toString () { A         returntoString (value); -}

As the note indicates, the ToString () method of the integer returns the string form of the value of the int type that corresponds to the integer object.

1 //test The return result of the ToString method of the integer2Integer num=NewInteger (61);3String s =num.tostring ();4           //Judging the reference s to the object type5           if(sinstanceofString)6System.out.println ("String type refers to the object that the variable s is pointing to is a string Object!") ");7           //Judging s points to what the object contains8           if(S.equals ("61"))9System.out.println ("s=" +61);

(2) When this happens: System.out.println (The object's reference (not a String type reference)), the ToString method that refers to the object is called, and the result of the call is output to the console. For example, here System.out.println (a); the ToString () method of the integer object referenced by a refers to the call and is output to the console. By (1) know. The result of the call is the string "6". and is output to the console. So what you see in the console is 6 instead of [email protected] numbers

2015-09-11 Issue (II)

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.