ToString class generally used to represent the generated output in human readable or textual format. It extends from java.lang.Object class.
Generally, toString method converts the object's value to a string therefore an object can be represented textually. You can use toString especially for login or debugging purpose. But the main idea behind it is that toString should be used whenever you are looking to change a datatype to string.
a simple example:
int value = 7;
String str = Integer.toString(value); //now str is equal to 7
System.out.println("My value: " + str);
the output is:
My value: 7
In the above example you can see that toString method is used to convert the primitive values into string type.
Posted on: April 6, 2005 If you enjoyed this post then why not add us on Google+? Add us to your Circles