How do I get a specific element from a List ?
Double[] weightArray = {240.0, 220d, 230.0, 240.0, 250.0,220.0, 215.0, 220.0,215d,223d};
Double[] pulseArray= {72.0,74.0,75.0,76.0,72.0,78.0,62.0,78.0,76.0,73.0,73.0,79.0};
Double[] sysArray={120.0,120.0,120.0,120.0,120.0,120.0,120.0,120.0,120.0,120.0};
Double[] diaArray={80.0,80.0,80.0,80.0,80.0,80.0,80.0,80.0,80.0,80.0};
List<double[]> values = new ArrayList<double[]>();
for(int i=0; i<weightArray.length; i++){
values.add(new double[] {weightArray[0], weightArray[1], weightArray[2], weightArray[3], weightArray[4], weightArray[5], weightArray开发者_高级运维[6], weightArray[7],weightArray[8], weightArray[9] });
values.add(new double[] {pulseArray[0],pulseArray[1],pulseArray[2],pulseArray[3],pulseArray[4],
pulseArray[5],pulseArray[6],pulseArray[7],pulseArray[8],pulseArray[9] });
values.add(new double[] {sysArray[0],sysArray[1],sysArray[2],sysArray[3],sysArray[4],
sysArray[5],sysArray[6],sysArray[7],sysArray[8],sysArray[9] });
values.add(new double[] {diaArray[0],diaArray[1],diaArray[2],diaArray[3],diaArray[4],
diaArray[5],diaArray[6],diaArray[7],diaArray[8],diaArray[9] });
}
// Does not work
//Object element =values.get(3,2);
//String s= element.toString();
//Toast.makeText(context, s.toString() , Toast.LENGTH_SHORT).show();
For example, I want to get values element 3,2, (diaArrray[1] )
values.get(listIndex)[arrayIndex]
should do it.
You might also try changing
Double[]
to
double[]
unless you have a compelling reason to want an array of Double
s. That will lead to auto-boxing confusion down the road.
And inside
for(int i=0; i<weightArray.length; i++){ ... }
you're not actually using i
which looks suspicious to me.
How do I get a specific element from a List ?
To get an element from a List, use the get(int)
method.
This will return your primitive double array. Then pick an element out of that array.
double d = values.get(3)[2];
Be aware of the fact that you can simply add the arrays this way:
double[] weightArray = {240.0d, 220.0d, 230.0d, 240.0d, 250.0d, 220.0d, 215.0d, 220.0d, 215.0d, 223.0d};
List<double[]> values = new ArrayList<double[]>();
values.add(weightArray);
精彩评论