public void dataAnalytics()
{
double sum=0;
double i=0;
double minage=20;
double maxage=20;
System.out.println("dataAnalytics for the Rural region");
for (Record ee :RList)
{
sum=sum+Double.valueOf(ee.getIncome());
i++;
}
ageComparator sc = new ageComparator();
Collections.sort(RList, sc);
maxage = (RList[0]).getAge();
minage = (RList[ records.length - 1]).getAge();
System.out.println("Average income for the Rural region is : $"+sum/i);
System.out.println("Min age for the Rural region is : "+minage);
System.out.println("Max age for the Rural region is : "+maxage);
}
I am trying to access a variable in the first object of the array and the last object of the arrayList which will give me the min age and max age from the arraylist. This line is giving me the eror::
maxage = (RList[0]).getAge();
minage = (RList[ records.length - 1]).getAge();
any ideas/
The array list is not indexed using the square braces but using getters, try:
See here for details. http://docs.oracle.com/javase/1.4.2/docs/api/java/util/ArrayList.html
To use array syntax you can use