logo CodeStepByStep logo

collectionMystery1

Language/Type: Java collections ArrayList

Write the output produced by the following method when passed each of the following lists:

public static void collectionMystery1(ArrayList<Integer> list) {
    for (int i = 0; i < list.size(); i++) {
        int n = list.get(i);
        list.remove(i);
        if (n % 2 == 0) {
            list.add(i);
        }
    }
    System.out.println(list);
}
{5, 2, 5, 2}
{3, 5, 8, 9, 2}
{0, 1, 4, 3, 1, 3}

You must log in before you can solve this problem.

Log In

Need help?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.