Developing Algorithms Using ArrayLists

AP Computer Science A· difficulty 4/5

ArrayList<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
list.add(3);
list.add(1, 99);
list.remove(2);
System.out.println(list);

What is printed?

  • A

    [1, 99, 3]

    check_circle
  • B

    [99, 1, 3]

  • C

    [1, 2, 3]

  • D

    [1, 99, 2]

Explanation

After add(1, 99) the list is [1, 99, 2, 3]. Then remove(2) removes the element at index 2 (which is 2), giving [1, 99, 3].

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

Related questions