Raj Tandel Raj Tandel - 1 year ago 82
Java Question

How to access specific element of array stored in arraylist?

I have following code

List<double[]> alParent = new ArrayList<>();
alParent.add(new double[]{15.22,25.22});
alParent.add(new double[]{1.1,2.3});
double tempone[] = {1,2};
double temptwo[] = {4,5};

I have stored array of type
inside arraylist.
I want to access elements from arraylist which are on first position and second position
array. For my example I want to access
separately. Is there any way i can get specific elements stored inside arraylist?
Also, if i have more elements in arraylist how do i get my desire result?

Answer Source

use blow code:

double temp1[] = new double[alParent.size()];    
double temp2[] = new double[alParent.size()];    
for (int i = 0; i < alParent.size(); i++) {    
    temp1[i] = alParent.get(i)[0];    
    temp2[i] = alParent.get(i)[1];    

temp1 and temp2 are arrays you want.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download