+ 3
How do I merge two string arrays together?
2 ответов
+ 6
String.join() perhaps?
https://code.sololearn.com/cF8g9H97J93y/?ref=app
+ 1
private static final String[] arr1 = new {"Max", "Leo"};
private final static String[] arr2 = new {"Bob", "Shaun", "Thom"};
for (int i =0;i < arr1.length; i++) {
sumArr[i] = arr1[i];
}
for (int i = 0; i < arr2.length; i++) {
sumArr[i + arr1.length] = arr2[i]
}
System.out.println(Arrays.toString(sumArr));
Arrays.toString() - first need to import java.util.Arrays;
Or
System.arraycopy(arr1, 0, sumArr, 0, arr1.length);
System.arraycopy(arr2, 0, sumArr, 2, arr2.length);