Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | import java.io.CharArrayWriter; public class JavaCharArrayWriter { public static void main(String[] args) { CharArrayWriter charWriter = new CharArrayWriter(); try { String str = "Welcome To code4example.com"; charWriter.write(str); char[] chars = charWriter.toCharArray(); for (char c : chars) { System.out.print(c); } } catch (Exception ex) { System.out.println(ex.getMessage()); } charWriter.close(); } } |
The java.io.CharArrayWriter.toCharArray() method returns a array of character from this writer.