Why is there (Integer) casting?
Friends,
Code:
// Obtaining an array from an array list
import java.util.*;
class ArrayListToArray {
public static void main(String[] args) {
ArrayList al = new ArrayList();
al.add(new Integer(1));
al.add(new Integer(2));
al.add(new Integer(5));
al.add(new Integer(9));
System.out.println("The contents of the array list are" + al);
Object ia[] = al.toArray();
int sum = 0;
for(int i = 0; i < ia.length; i++)
sum += ((Integer)ia[i]).intValue();
System.out.println("The sum is" + sum);
}
}
What does this statement does?
Code:
sum += ((Integer)ia[i]).intValue();
Why is there (Integer) casting in the above code?
Thanks a lot.