import java.util.ArrayList;

public class Filter {

    public static void main(String[] args) {
        ArrayList<Integer> myList = new ArrayList<Integer>();
        myList.add(1);
        myList.add(2);
        myList.add(3);
        myList.add(5);
        myList.add(7);
        myList.add(8);
        filterEven(myList);
        System.out.println(myList);
    }

    // Remove all the uneven elements from the given ArrayList
    // Precondition: values != null
    // Postcondition: values contains only even elements
    static void filterEven(ArrayList<Integer> values) {

        int pos = 0;

        while (pos < values.size()) {
            if (values.get(pos) % 2 != 0) {
                values.remove(pos);
            } else {
                pos++;
            }
        }
    }


}