CharArrayWriter write(int) in Java

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

Syntax:

void java.io.CharArrayWriter.write(int c)

This method takes one argument. This method writes a character to the buffer.

Parameters: One parameter is required for this method.

c: int specifying a character to be written.

Returns: NA

Exceptions: NA

Approach

Java

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

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

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

        int c = 'M';
        charArrayWriter.write(c);

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

Output:

abcdM


No comments:

Post a Comment