Java StringWriter(int initialSize) Constructor

Syntax

StringWriter(int initialSize) constructor from StringWriter has the following syntax.

public StringWriter(int initialSize)

Example

In the following code shows how to use StringWriter.StringWriter(int initialSize) constructor.


// w  w w .  j a v  a  2  s .  c om
import java.io.IOException;
import java.io.StringWriter;

public class Main {
  public static void main(String args[]) throws IOException {
    StringWriter outStream = new StringWriter(100);
    String s = "This is a test from j a va2s.com.";
    for (int i = 0; i < s.length(); ++i){
      outStream.write(s.charAt(i));
    }  
    System.out.println("outstream: " + outStream);
    System.out.println("size: " + outStream.toString().length());
  }
}

The code above generates the following result.