logo Practice-It logo

ArrayList Mystery

Language/Type: Java ArrayLists Collections mystery
Author: Marty Stepp and Helene Martin (on 2014/02/13)

Consider the following method:

public static void mystery(ArrayList<Integer> list) {
    for (int index = 0; index < list.size(); index++) {
        int elementValue = list.remove(index);
        if (elementValue % 2 == 0) {
            list.add(index);
        }
    }
    System.out.println(list);
}

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

[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

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

Is there a problem? Contact a site administrator.