Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array Confusion with Doubles/doubles

Tags:

java

arrays

I have two Arrays that are initialized as such:

    public static double[] arrayweight= new double[100];
    public static double[] arraypulse= new double[100];

They are filled with data e.g. 23.0,25.8....etc.

I need to combine the two Arrays into one array of double[]

I have chosen to use the following approach which does not work. Any ideas?

     ArrayList <Double> al = new ArrayList<Double>();

// The following methods do not work ;(     
     al.add((double[]) Global.arrayweight);
     al.add(new Double(Global.arraypulse));
like image 618
Trey Balut Avatar asked Aug 26 '26 10:08

Trey Balut


1 Answers

You can achieve it using System.arraycopy.

double[] cArray= new double[Arrayweight.length + Arraypulse.length];
System.arraycopy(Arrayweight, 0, cArray, 0, Arrayweight.length);
System.arraycopy(Arraypulse, 0, cArray, Arrayweight.length, Arraypulse.length);
like image 114
Mahesh Avatar answered Aug 28 '26 01:08

Mahesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!