CharArrayWriter append(char) in Java

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

Syntax:

CharArrayWriter java.io.CharArrayWriter.append(char c)

This method takes one argument. This method appends the specified character to this writer.

Parameters: One parameter is required for this method.

c: The 16-bit character to append.

Returns: This writer.

Exceptions: NA

Approach

Java

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

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

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

        char c = 'd';
        charArrayWriter.append(c);
        System.out.println(charArrayWriter.toString());
        charArrayWriter.close();
    }
}

Output:

abcd

No comments:

Post a Comment