String 类的 toCharArray() 方法将此字符串转换为字符数组。示例实时演示导入 java.lang.*;公共类 StringDemo { public static void main(String[] args) { //将 String 值转换为字符数组类型值 String str = " Java was developed by James Gosling"; char retval[] = str.toCharArray(); //显示转换后的值 System.out.println("转换为字符数组的值 = "); System.out.println(retval); } }输出转换为字符数组的值 = Java was developed by James Gosling