dynamic cumulation in ArrayList using java
Hi,
See the Below example, I added the values in ArrayList.These values I am fetching in loop. These iterator values I want to get it cumulative way. Values are dynamic. I am expecting the result like below
Actual valuecumulative value
10 10
20 30(10+20)
30 60(30+30)
50 110(60+50)
80 190(80+110) like result I am expecting.
Please see the below code and change if any modification required.
int value;
int A1=30;
int A2=300;
int B1=40;
int B2=400;
int C1=20;
int C2=200;
int D1=10;
int D2=100;
int tots=A1+A2;
int tot = 0;
int to = 0;
Bean b=new Bean();
ArrayList al=new ArrayList();
al.add(new Integer(A1));
al.add(new Integer(B1));
al.add(new Integer(C1));
al.add(new Integer(D1));
Iterator it=al.iterator();
for(int i=0;i<al.size();i++){
b.setObjValue(al.get(i));
Integer k=(Integer) b.getObjValue();
System.out.println(b.getObjValue()+" -- "+k );
double d=0;
d=d+k;
}
Awating for any + ve response with result.>

