Java StringWriter.toString()

Syntax

StringWriter.toString() has the following syntax.

public String toString()

Example

In the following code shows how to use StringWriter.toString() method.


import java.io.*;
/* www  .j av  a  2s .  c om*/
public class Main {

   public static void main(String[] args) {

      
      StringWriter sw = new StringWriter();

      // write a string
      sw.write("tutorial from java2s.com");

      
      System.out.println(sw.toString());


   }
}

The code above generates the following result.