logo Practice-It logo

BJP5 Self-Check 10.18: ArrayListMystery4

Language/Type: Java ArrayList Collections mystery
Author: Eric Spishak (on 2019/09/19)

Consider the following method:

public static void mystery4(ArrayList<Integer> list) {
    for (int i = 0; i < list.size(); i++) {
        int element = list.get(i);
        list.remove(i);
        list.add(0, element + 1);
    }
    System.out.println(list);
}

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

[10, 20, 30]
[8, 2, 9, 7, 4]
[-1, 3, 28, 17, 9, 33]

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.