java中如何将字符串变成字符数组?

2024-12-20 05:47:38
推荐回答(5个)
回答1:

public class Test {
public static void main(String[] args) {
String str = "asfewgt";
char[] ch = str.toCharArray();
for (int i = 0; i < ch.length; i++) {
System.out.print(String.valueOf(ch[i]) + '\t');
}
}
}

回答2:

这样可以:

public class Print {
public static void main(String[] args) {
String s = "dfjlskdf";
char [] ss = s.toCharArray();

}
}

回答3:

String str = "abcdefg";
char[] cha = str.toCharArray();

回答4:

String str = "123";
char [] chs = str.toCharArray();

回答5:

干嘛去了,赶紧结贴啊。浪费我时间