Retrive numeric values from an ArrayList
ArrayList a= new ArrayList();
a.add(1);
a.add(1.78);
a.add('A');
a.add("Hello");
a.add(78);
double sum=0;
for(Object o:a)
{
Number d=null;
// cast the object based on type and use it
if(o instanceof Number)
{
d=(Number)o;
sum =sum+d.doubleValue();
}
}
System.out.print(sum);}