Java.io.StringWriter.getBuffer() Method


Advertisements


Description

The java.io.StringWriter.getBuffer() method returns the string buffer itself.

Declaration

Following is the declaration for java.io.StringWriter.getBuffer() method.

public StringBuffer getBuffer()

Parameters

NA

Return Value

This method returns stringBuffer holding the current buffer value.

Exception

NA

Example

The following example shows the usage of java.io.StringWriter.getBuffer() method.

package com.tutorialspoint;

import java.io.*;

public class StringWriterDemo {

   public static void main(String[] args) {
   
      // create a new writer
      StringWriter sw = new StringWriter();

      // write a string
      sw.write("Hello World");

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

   }
}

Let us compile and run the above program, this will produce the following result −

Hello World

java_io_stringwriter.htm

Advertisements