+ 3

How do I merge two string arrays together?

5th Nov 2017, 2:32 AM
William Rodriguez
William Rodriguez - avatar
2 Antworten
5th Nov 2017, 3:22 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 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);
5th Nov 2017, 2:25 PM
Лариса Лариса
Лариса Лариса - avatar