CharArrayWriter toString() in Java

toString(): This method is available in the java.io.CharArrayWriter class of Java.

Syntax:

String java.io.CharArrayWriter.toString()

This method converts input data to a string.

Parameters: NA

Returns: the string.

Exceptions: NA

Approach

Java

import java.io.CharArrayWriter;
import java.io.IOException;

public class CharArrayWritertoString {
    public static void main(String[] args) throws IOException {
        CharArrayWriter charArrayWriter = new CharArrayWriter();

        char cbuf[] = { 'a', 'b', 'c', 'd' };
        charArrayWriter.write(cbuf);

        System.out.println(charArrayWriter.toString());
        charArrayWriter.close();
    }
}

Output:

abcd


No comments:

Post a Comment