Is there a simple way like one line of code to combine two arrays of double type into one array?
If there isn't, what would be the easiest way to do it?
Thanks
If you have liberty of using Apace commons this here is the solution.
Or you could write some like this:
public static double[] unite(double[]... arrays)
{
int length = 0;
for(double[] array: arrays)
length += array.length;
double[] united = new double[length];
int pos = 0;
for(double[] array: arrays) {
System.arraycopy(array, 0, united, pos, array.length);
pos += array.length;
}
return united;
}
public static void main(String... args) {
double[] d1 = {0.1, 0.2};
double[] d2 = {0.3, 0.4, 0.5};
double[] d3 = {0.6, 0.7, 0.8, 0.9};
double[] d4 = {};
double[] d5 = {1.0};
double[] united = unite(d1, d2, d3, d4, d5);
System.out.println(Arrays.toString(united));
}