Answer: Following is the program to copy the multiple arrays into single array:
public MergeArray{
public static void main(String args[]){
int[] arr1 = {1,2,3,4,5};
int[] arr2 = {6,7,8,9,10};
int lenCopy = arr1.length+arr2.length;
int[] arrCopy = new int[lenCopy];
int count = 0;
for(int num:arr1){
arrCopy[count++] = num;
}
for(int num:arr2){
arrCopy[count++] = num;
}
}
}
Explanation: We initialized two arrays, arr1 and arr2, and calculated their combined length, storing it in the lenCopy variable.
Next, we created a third array, arrCopy, with a length equal to lenCopy.
Using two enhanced for-loops, we copied all elements from arr1 and arr2 into arrCopy.
As a result, arrCopy contains all the elements from both arrays, effectively merging them into a single array.