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)