Java CharArrayWriter.toString()

Syntax

CharArrayWriter.toString() has the following syntax.

public String toString()

Example

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


/*www . j  a va  2  s. c o m*/

import java.io.CharArrayWriter;

public class Main {
  public static void main(String[] args) throws Exception {

    char[] ch = { 'A', 'B', 'C', 'D', 'E' };


    CharArrayWriter chw = new CharArrayWriter();

    // write character buffer to the writer
    chw.write(ch);

    // get buffered content as string
    String str = chw.toString();

    // print the string
    System.out.print(str);

  }
}

The code above generates the following result.