The ToString () method in Java
Directory
The ToString () method in Java
1.???? The ToString method of the object
2.???? The ToString method of the base type
3.???? The ToString method of the array
4.???? Reference documents
?
?
- The ToString method of the object
in the JDK API in the Object object that toString The method is described as follows:
toString :
Public String toString ()
Returns the string representation of the object. Typically, tostring method returns a " in text mode " It is recommended that all subclasses override this method.
Object Class of toString method returns a string that consists of the class name (the object is an instance of the class), at Tag Character "@" and an unsigned hexadecimal representation of the hash code for this object. In other words, the method returns a string whose value is equal to:
GetClass (). GetName () + ' @ ' + integer.tohexstring (hashcode ())
Return:
The string representation of the object.
?
Conclusion:
???? if the ToString method is overridden in the object , the object's own tostring method is called, otherwise the the toString method.
?
- The ToString method of the base type
Basic types of toString method is called by the Java.io.PrintStream of the println (int) method, the key code is as follows:
Write (string.valueof (i));
?
can be done by JDK self-bringing tools JAVAP Anti-compile code to view.
find the generated . Class the directory where the file is located, execute the command:
Javap–c class name
?
- The ToString method of the array
For arrays:
Code:
int[] arr = new int[] {1, 2, 3};
System.out.println (arr);
Output content:
[[Email protected]
?
Conclusion:
An array is also an object, and an array object is not instantiated from a class, but by the JVM created directly, This is called the toString method of the java.lang.Object .
?
?
?
- Reference documents
JDK API
JAVA is the array in the object?
The ToString () method in Java