ArrayList Methods

AP Computer Science A· difficulty 3/5

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

What is printed?

  • A

    [1, 99, 2, 3]

  • B

    [1, 2, 3, 99]

  • C

    [99, 2, 3]

  • D

    [99, 1, 2, 3]

    check_circle

Explanation

add(0, 99) inserts at the front, shifting all other elements right.

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

Related questions