Traversing ArrayLists

AP Computer Science A· difficulty 2/5

ArrayList<Integer> list = new ArrayList<>();
list.add(10);
list.add(20);
list.add(30);
for (int i = 0; i < list.size(); i++) {
    list.set(i, list.get(i) + 1);
}
System.out.println(list);

What is printed?

  • A

    [11, 22, 33]

  • B

    [1, 2, 3]

  • C

    [11, 21, 31]

    check_circle
  • D

    [10, 20, 30]

Explanation

Each element is replaced by itself plus 1: 11, 21, 31.

Want 10 more like this — adaptive to your weak spots?

Related questions