String 与 char[]之间的转换
作者:互联网
String --> char[]:调用String的toCharArray()
char[] --> String:调用String的构造器
@Test
public void test2(){
String str1 = "abc123"; //题目: a21cb3
char[] charArray = str1.toCharArray();
for (int i = 0; i < charArray.length; i++) {
System.out.println(charArray[i]);
}
char[] arr = new char[]{'h','e','l','l','o'};
String str2 = new String(arr);
System.out.println(str2);
}
标签:arr,转换,String,System,char,charArray,out 来源: https://www.cnblogs.com/leyzzz/p/15306094.html