CharArrayWriter toCharArray() method in Java with examples Last Updated : 14 Feb, 2022 Comments Improve Suggest changes Like Article Like Report The toCharArray() method of the CharArrayWriter class in Java returns a copy of the input data.Syntax: public char[] toCharArray() Parameters: This method does not accept any parameter.Return Value: This method returns a copy of the input data. Below program illustrate the above method: Program 1: Java // Java program to illustrate // the toCharArray() method import java.io.*; public class GFG { public static void main(String[] args) throws IOException { // Initializing String Writer CharArrayWriter geek_writer1 = new CharArrayWriter(); char[] Sw = { 'G', 'E', 'E', 'K', 'S' }; for (char c : Sw) { // Use of append(char Sw) : geek_writer1.append(c); } // Use of toCharArray() : char[] toChar1 = geek_writer1.toCharArray(); for (char c1 : toChar1) { System.out.println("toCharArray : " + c1); } } } Output: toCharArray : G toCharArray : E toCharArray : E toCharArray : K toCharArray : S Program 2: Java // Java program to illustrate // the toCharArray() method import java.io.*; public class GFG { public static void main(String[] args) throws IOException { // Initializing String Writer CharArrayWriter geek_writer1 = new CharArrayWriter(); char[] Sw = { 'G', 'O', 'P', 'A', 'L', 'D', 'A', 'V', 'E' }; for (char c : Sw) { // Use of append(char Sw) : geek_writer1.append(c); } // Use of toCharArray() : char[] toChar1 = geek_writer1.toCharArray(); for (char c1 : toChar1) { System.out.println("toCharArray : " + c1); } } } Output: toCharArray : G toCharArray : O toCharArray : P toCharArray : A toCharArray : L toCharArray : D toCharArray : A toCharArray : V toCharArray : E Reference: https://docs.oracle.com/javase/10/docs/api/java/io/CharArrayWriter.html#toCharArray() Comment More infoAdvertise with us Next Article CharArrayWriter toCharArray() method in Java with examples gopaldave Follow Improve Article Tags : Java Java-Functions Java-IO package Java-CharArrayWriter Practice Tags : Java Similar Reads CharArrayWriter toString() method in Java with examples The toString() method of the CharArrayWriter class in Java converts the given input data to a string. Syntax: public String[] toString() Parameters: This method does not accept any parameter. Return Value: This method returns a copy of the input data. Below program illustrate the above method: Progr 1 min read CharArrayWriter write() method in Java with Examples The write() method of CharArrayWriter class in Java is of three types: The write(int) method of CharArrayWriter class in Java is used to write a character to the writer in form of an integer. This write() method writes one character at a time to the CharArrayWriter.Syntax: public void write(int c) O 3 min read CharArrayWriter size() method in Java with examples The size() method of the CharArrayWriter class in Java is used to get the current size of the buffer. Syntax: public int size() Parameters: This method does not accept any parameter.Return Value: This method returns an integer value which signifies the current size of the buffer. Below program illus 2 min read CharArrayWriter writeTo() method in Java with Examples The writeTo(Writer) method of CharArrayWriter class in Java is used to write the contents of the CharArrayWriter to another character stream.Syntax: public void writeTo(Writer out) throws IOException Parameters: This method accepts one parameter out that represents the output stream that is the dest 1 min read CharArrayReader ready() method in Java with Examples The ready() method of CharArrayReader Class in Java is used to check whether this CharArrayReader is ready to be read or not. It returns a boolean which states if the reader is ready. Syntax: public void ready() Parameters: This method does not accepts any parameters Return Value: This method return 3 min read Like