StringWriter toString() method in Java with Examples Last Updated : 30 Oct, 2019 Comments Improve Suggest changes Like Article Like Report 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. Return Value: This method returns a String value which is the String representation of the StringWriter instance. Below methods illustrates the working of toString() method: Program 1: Java // Java program to demonstrate // StringWriter toString() method import java.io.*; class GFG { public static void main(String[] args) { try { // Create a StringWriter instance StringWriter writer = new StringWriter(); // Get the String // to be written in the stream String string = "GeeksForGeeks"; // Write the string // to this writer using write() method writer.write(string); System.out.println("String representation: " + writer.toString()); } catch (Exception e) { System.out.println(e); } } } Output: String representation: GeeksForGeeks Program 2: Java // Java program to demonstrate // StringWriter toString() method import java.io.*; class GFG { public static void main(String[] args) { try { // Create a StringWriter instance StringWriter writer = new StringWriter(); // Get the String // to be written in the stream String string = "GFG"; // Write the string // to this writer using write() method writer.write(string); System.out.println("String representation: " + writer.toString()); } catch (Exception e) { System.out.println(e); } } } Output: String representation: GFG Comment More infoAdvertise with us Next Article StringWriter toString() method in Java with Examples C code_r Follow Improve Article Tags : Java Java-Functions Java-IO package Java-StringWriter Practice Tags : Java Similar Reads String toString() Method in java with Examples 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 : publ 1 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 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 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 Provider toString() method in Java with Examples The toString() method of java.security.Provider class is used to return a string with the name and the version number of this provider. Syntax: public String toString() Return Value: This method returns the string with the name and the version number for this provider. Below are the examples to illu 2 min read Like