Home Tutorial Java StringExamples java.lang.String.toString()

 
 

Share on Google+Share on Google+
java.lang.String.toString()
Posted on: April 6, 2005 at 12:00 AM
Advertisement
ToString class generally used to represent the generated output in human readable or textual format. It extends from java.lang.Object class.

ToString class generally used to represent the generated output in human readable or textual format. It extends from java.lang.Object class.

Syntax:

objectName.toString()

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.

Example Codes

Generic toString

Convert Date to String

Convert Character into a String

Advertisement

Related Tags for java.lang.String.toString():


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 6, 2005

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com