I want to unite two int arrays in Java. How can I improve the code? Maybe there is a function that already does that?
public class Unify{
public static void main(String[] argv){
int[] a = {1, 2, 3};
int[] b = {4, 5, 6};
int[] c = mylist(a, b);
for (int x:c)
System.out.println(x);
}
public static int[] mylist(int[] a, int[] b){
int len = a.length + b.length;
int[] c = new int[len];
for(int i = 0; i < a.length; i++)
c[i] = a[i];
for(int i = a.length, j = 0; i < len; i++, j++)
c[i] = b[j];
return c;
}
}