1 /* 2 String 与 char[]之间的转换 3 4 String----> char[]:调用String的toCharArray() 5 char[] ---->String:调用String的构造器 6 */ 7 @Test 8 public void test6(){ 9 String str1 = "abc123"; 10 11 char[] charArray = str1.toCharArray(); 12 for(int i =0;i <charArray.length;i++){ 13 System.out.println(charArray[i]); //a b c 1 2 3 14 } 15 16 char[] arr = new char[]{'h','e','l','l','o'}; 17 String str2 = new String(arr); 18 System.out.println(str2); //hello 19 20 }