String toString() Method in java with Examples Last Updated : 11 Jul, 2018 Comments Improve Suggest changes Like Article Like Report String toString() is the built-in method of java.lang which return itself a string. So here no actual conversion is performed. Since toString() method simply returns the current string without any changes, there is no need to call the string explicitly, it is usually called implicitly. Syntax : public String toString() Parameter: The method does not accept any parameters . Return Value: This method returns the string itself. Examples : Input: String("geeksforgeeks") Output: geeksforgeeks Below programs illustrate the Java.lang.String.toString() method: Program 1: java // Java program to illustrate the // Java.lang.String.toString() method import java.io.*; public class Geeks { public static void main(String args[]) { String Strobj = new String("Welcome to the world of geeks."); System.out.print("Output String Value :"); System.out.println(Strobj.toString()); String Strobj2 = new String("Let's make it simple for you."); System.out.print("Output String Value :"); System.out.println(Strobj2.toString()); } } Output: Output String Value :Welcome to the world of geeks. Output String Value :Let's make it simple for you. Program 2: java // Java program to illustrate the // Java.lang.String.toString() method import java.io.*; public class Geeks { public static void main(String args[]) { String Strobj = new String("THank You"); System.out.print("Output : "); System.out.println(Strobj.toString()); } } Output: Output : THank You Comment More infoAdvertise with us Next Article String toString() Method in java with Examples A ankita_chowrasia Follow Improve Article Tags : Java Java-Strings Practice Tags : JavaJava-Strings Similar Reads StringWriter toString() method in Java with Examples The toString() method of StringWriter Class in Java is used to get the String representation of this StringWriter instance. This method does not accept any parameter and returns the required String value. Syntax: public String toString() Parameters: This method accepts does not accepts any parameter 2 min read StringBuffer toString() method in Java with Examples The toString() method of StringBuffer class is the inbuilt method used to returns a string representing the data contained by StringBuffer Object. A new String object is created and initialized to get the character sequence from this StringBuffer object and then String is returned by toString(). Sub 2 min read StringBuilder toString() method in Java with Examples The toString() method of the StringBuilder class is the inbuilt method used to return a string representing the data contained by StringBuilder Object. A new String object is created and initialized to get the character sequence from this StringBuilder object and then String is returned by toString( 3 min read Pattern toString() Method in Java with Examples toString() method of a Pattern class used to return the string representation of this pattern. This return the regular expression from which this pattern was compiled. Syntax: public String toString() Parameters: This method accepts nothing as parameter. Return value: This method returns a string re 1 min read Optional toString() method in Java with examples The toString() method of java.util.Optional class in Java is used to get the string representation of this Optional instance. Syntax: public String toString() Parameters: This method accepts nothing. Return value: This method returns the string representation of this Optional instance. Below program 1 min read Like