Writing method to insert a[] into numbers[] at a position stored in variable "location".
public boolean insertArray(int location, double a[])
{
if (length != MAX_CAPACITY)
{
numbers[location] = a[];
length++;
return true;
}
return false;
}
Is it possible to pass through an array?
You can use System.arraycopy
:
public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
Here is a simple example you can follow to solve your problem :
double a[] = {1, 2, 3, 4, 5};
double b[] = {6, 7, 8};
int local = 5;
double result[] = new double[a.length + b.length];
System.arraycopy(a, 0, result, 0, a.length);
System.arraycopy(b, 0, result, local, b.length);
System.out.println(Arrays.toString(result));
Output
[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With