Java String toCharArray()方法示例。
String类的toCharArray()方法将此字符串转换为字符数组。
示例
import java.lang.*; public class StringDemo { public static void main(String[] args) { //将字符串值转换为字符数组类型值 String str = " Java was developed by James Gosling"; char retval[] = str.toCharArray(); //显示转换后的值 System.out.println("Converted value to character array = "); System.out.println(retval); } }
输出结果
Converted value to character array = Java was developed by James Gosling