Here a simple function that use variable arguments:
final static
public int[] merge(final int[] ...arrays ) {
int size = 0;
for ( int[] a: arrays )
size += a.length;
int[] res = new int[size];
int destPos = 0;
for ( int i = 0; i < arrays.length; i++ ) {
if ( i > 0 ) destPos += arrays[i-1].length;
int length = arrays[i].length;
System.arraycopy(arrays[i], 0, res, destPos, length);
}
return res;
}
To use:
int[] array1 = {1,2,3};
int[] array2 = {4,5,6};
int[] array3 = {7,8,9};
int[] array1and2and3 = merge(array1, array2, array3);
for ( int x: array1and2and3 )
System.out.print( String.format("%3d", x) );