public void dataAnalytics()
{
double sum=0;
System.out.println("dataAnalytics for the Rural region");
for (Record ee :RList)
{
sum=sum+RList.get(4);
}
}
I have a very simple problem here , i am a novice java programmer , so please do be easy with me. I have an arrayLisl “Rlist” which has income in 4th index. What i am trying to accomplish is to get the sum of all income elements in the arraylist. I have tried sum=sum+RList.get(4); but i does not seem to work .
income is initialized as double inthe super class but is passed in the arraylist constructor as string.
What is the use of
eein the loop? It is unused there.Assuming you have an arraylist of
Recordobjects and you are able toaccess their income fields via a getter method like
getIncome()which returns a string, you should do that: