Java IO Tutorial - 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.*;
//w  w  w .  j a v  a  2 s  . co  m
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.