import java.util.ArrayList;

public class ArrayList_Practice {
    public static void main(String[] args) {
        ArrayList alist = new ArrayList(21357);
        System.out.println(alist);
        populateWithIntegers(alist, 10);
        System.out.println(alist);
        System.out.println(sum(alist));
        deleteEveryOther(alist);
        System.out.println(alist);
    }
    
    public static void populateWithIntegers(ArrayList alist,
            int n) {
        for (int i = 0; i <= n; i++) {
            alist.add(i*i);
        }
    }
    
    public static int sum(ArrayList alist) {
        int sum = 0;
        for (int num : alist) {
            sum += num;
        }
        return sum;
    }
    
    public static void deleteEveryOther(ArrayList alist) {
        int posn = 0;
        for (int i = 0; i < alist.size(); i++) {
            alist.remove(i);
        }
    }
}