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 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 Stack toString() method in Java with Example The toString() method of Java Stack is used to return a string representation of the elements of the Collection. The String representation comprises a set representation of the elements of the Collection in the order they are picked by the iterator closed in square brackets[].This method is used mai 2 min read Scanner toString() method in Java with Examples The toString() method of java.util.Scanner class returns the string representation of this Scanner. The exact format is unspecified. Syntax: public String toString() Return Value: This function returns the string representation of this scanner. Below program illustrates the above function: Program 1 1 min read OptionalLong toString() method in Java with examples The toString() method help us to get a non-empty string representation of this OptionalLong.This non-empty string representation is suitable for debugging. The exact presentation format is unspecified and may vary between implementations and versions. Syntax: public String toString() Parameters: Thi 1 min read Package toString() method in Java with Examples The toString() method of java.lang.Package class is used to get the String representation of this package instance. The method returns the String representation as a String value. Syntax: public String toString() Parameter: This method does not accepts any parameter. Return Value: This method return 1 min read StringBuffer substring() method in Java with Examples In StringBuffer class, there are two types of substring method depending upon the parameters passed to it. substring(int start) The substring(int start) method of StringBuffer class is the inbuilt method used to return a substring start from index start and extends to end of this sequence. The strin 4 min read Like