Java CharArrayWriter.toCharArray()方法示例

广告位

Java CharArrayWriter.toCharArray()方法示例 CharArrayWriter的…

Java CharArrayWriter.toCharArray()方法示例

CharArrayWriterCharArrayWriter.toCharArray()方法的语法如下。

public char[] toCharArray()  

示例

在下面的代码中展示了如何使用CharArrayWriter.toCharArray()方法。

import java.io.CharArrayWriter;    public class Main {    public static void main(String[] args) throws Exception {      CharArrayWriter chw = new CharArrayWriter();        String str = "from yiibai.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 // By: WWW .Y ii baI.CO m        System.out.println(c);      }      }  }  

上面的代码生成以下结果。

f  r  o  m    y  i  i  b  a  i  .  c  o  m  !  

  

洁姐我爱你

关于作者: 洁姐我爱你

为您推荐