1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
class MergeArray{ public static void main(String args[]){ int arr[] = {4,5,6,7,8}; int arr2[] = {9,10,11,12}; int merge[] = new int[(arr.length)+(arr2.length)]; for(int i=0; i<(arr.length);i++) merge[i] = arr[i]; for(int i=0; i<(arr2.length); i++) merge[i+arr.length] = arr2[i]; for(int i : merge) System.out.println(i); } } |
output
1 2 3 4 5 6 7 8 9 |
4 5 6 7 8 9 10 11 12 |
Compiled with JDK 9