java撥鍾
發布時間: 2024-07-16 21:16:09
Ⅰ java字元串數組合並 怎麼合並成一個數組
java字元串數組合並,可以使用array.復制方法,如下代碼:
packagecom.qiu.lin.he;
importjava.text.ParseException;
importjava.util.Arrays;
publicclassCeshi{
publicstaticvoidmain(String[]args)throwsParseException{
String[]str1={"J","a","v","a","中"};
String[]str2={"如","何","把","兩","個","數","組","合","並","為",
"一","個"};
intstrLen1=str1.length;//保存第一個數組長度
intstrLen2=str2.length;//保存第二個數組長度
str1=Arrays.Of(str1,strLen1+strLen2);//擴容
System.array(str2,0,str1,strLen1,strLen2);//將第二個數組與第一個數組合並
System.out.println(Arrays.toString(str1));//輸出數組
}
}
運行結果如下:
熱點內容