@Bambam has proposed some really good solutions and I would definitely apply one of them, if what you want always has to do with 2 same-sized arrays.
However, in case you want two have to different-sized arrays and independent of their type, you could use a solution similar to this:
public List<String> addRecursively(int index, Object[] array1, Object[] array2, List<String> list){
if(index < array1.length)
list.add(String.valueOf(array1[index]));
if(index < array2.length)
list.add(String.valueOf(array2[index]));
if(index >= array1.length && index >= array2.length)
return list;
return addRecursively(index+1, array1, array2, list);
}
Here is an example of how to use this method:
Integer[] arrayOfIntegers = new Integer[]{1,2,3,4,5};
String[] arrayOfStrings = new String[]{"a","b","c","d","e","f","g","h"};
List<String> unified = addRecursively(0,arrayOfStrings,arrayOfIntegers,new ArrayList<String>);
//output = a1b2c3d4e5f6g
for(String str:unified) System.out.print(str)
//output = [a, 1, b, 2, c, 3, d, 4, e, 5, f, 6, g]
System.out.println(Arrays.toString(list.toArray()));
PLEASE NOTE: You cannot use primitive types with this method. You arrays need to have wrapped primitive data types, something achieved with boxing.
If your arrays are already instantiated as primitive types, you could convert them in Java 8 like this:
int [] primitive = //some value here;
Integer[] wrapped = IntStream.of(primitive).boxed().toArray(Integer[]::new);
And you could definitely use a HashMap like the one from this answer and implement it in the aforementioned method.
I hope everyone finds this answer simple and comprehensible.