public class ssssss {
public static void main(String[] args){
String str1 = "Hello Java";
char c[] = str1.toCharArray();//将一个字符串变为字符数组toCharArray();
for (int i = 0; i<c.length;i++){
System.out.print(c[i] + ",");
}
System.out.println("");
String str2 = new String(c);//将全部的字符数组变为String字符串
System.out.println(str2);//输出字符串
String str3 = new String(c,0,3);//将部分的字符数组变为String ,从下表为0开始到下表为3结束;
System.out.println(str3);
}
//
}
结果:
H,e,l,l,o, ,J,a,v,a,
Hello Java
Hel