Java StringWriter.getBuffer()

Syntax

StringWriter.getBuffer() has the following syntax.

public StringBuffer getBuffer()

Example

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


/*  w  ww  .  j  a v a  2 s. com*/
import java.io.*;

public class Main {

   public static void main(String[] args) {

      
      StringWriter sw = new StringWriter();

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

      // print result by getting the buffer
      System.out.println("" + sw.getBuffer());


   }
}

The code above generates the following result.