toCharArray()方法
该方法的作用是返回一个字符数组,该字符数组中存放了当前字符串中的所有字符
public class toChar1{ public static void main(String[] args){ String s1=new String("I am Chinese"); char c[]=s1.toCharArray(); System.out.println("the length of c:"+c.length); System.out.println(c); System.out.println(new String(c)); String s2=new String(c,1,2); System.out.println(s2); } }
时间: 2024-10-06 00:11:11