Java CharArrayWriter.toCharArray()
Syntax
CharArrayWriter.toCharArray() has the following syntax.
public char[] toCharArray()
Example
In the following code shows how to use CharArrayWriter.toCharArray() method.
//from www. ja v a 2s . co m
import java.io.CharArrayWriter;
public class Main {
public static void main(String[] args) throws Exception {
CharArrayWriter chw = new CharArrayWriter();
String str = "from java2s.com!";
chw.write(str);
// get array of character from the writer
char[] ch = chw.toCharArray();
// for each character in character array
for (char c : ch) {
// print character
System.out.println(c);
}
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »