previous | start | next

Raw Type ArrayList (cont)

The raw type can be used (and you had to do this before generics were added to Java)

    1   public class RawTypeApp {
    2     public static void main(String[] args) {
    3       ArrayList lst = new ArrayList();
    4       for(int i = 0; i < 5; i++) {
    5         lst.add(i);
    6       }
    7       
    8       int sum = 0;
    9       
   10       for(int i = 0; i < lst.size(); i++) {
   11         sum = sum + (int) lst.get(i);  // cast specifies the type
   12       }
   13       System.out.printf("sum = %d\n", sum);
   14     }
   15   
   16   }


previous | start | next