Skip to content

Files

Latest commit

0e610f7 · Oct 13, 2019

History

History
32 lines (24 loc) · 948 Bytes

File metadata and controls

32 lines (24 loc) · 948 Bytes

Java - String toCharArray()方法

原文: https://beginnersbook.com/2013/12/java-string-tochararray-method-example/

方法toCharArray()在将String转换为字符序列后返回字符的Array。返回的数组长度等于String的长度,Array中的字符序列与String中的字符序列匹配。

 public char[] toCharArray()

示例:toCharArray()方法

在这个例子中,我们使用toCharArray()方法将String转换为char数组。

public class CharArrayExample{
   public static void main(String args[]){
       String str = new String("Welcome to BeginnersBook.com");
       char[] array= str.toCharArray();
       System.out.print("Content of Array:");
       for(char c: array){
           System.out.print(c);
       }
   }
}

输出:

Content of Array:Welcome to BeginnersBook.com