📜  Java String toCharArray() 示例

📅  最后修改于: 2022-05-13 01:54:29.324000             🧑  作者: Mango

Java String toCharArray() 示例

Java 字符串 toCharArray()方法将给定的字符串转换为字符序列。返回的数组长度等于字符串的长度。

句法 :

public char[] toCharArray()   
Return : It returns a newly allocated character array.
// Java program to demonstrate
// working of toCharArray() method
  
class Gfg {
    public static void main(String args[])
    {
        String s = "GeeksforGeeks";
        char[] gfg = s.toCharArray();
        for (int i = 0; i < gfg.length; i++) {
            System.out.println(gfg[i]);
        }
    }
}

输出:

G
e
e
k
s
f
o
r
G
e
e
k
s