Java:String转char数组

public char[]  toCharArray()
  • 将此字符串转换为一个新的字符数组。
    • 返回:
    • 一个新分配的字符数组,它的长度是此字符串的长度,而且内容被初始化为包含此字符串表示的字符序列。
    例如:
    public class Program{
    public static void main(String[] args)
    {
    String str = "This is a String."; // Convert the above string to a char array.
    char[] arr = str.toCharArray(); // Display the contents of the char array.
    System.out.println(arr);
    }
    }
    /*
    Output:
    This is a String.

版权声明:本文为HMYANG314原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。