ArrayList Methods

AP Computer Science A· difficulty 2/5

ArrayList<Integer> list = new ArrayList<>();
list.add(10);
list.add(20);
list.add(30);
list.set(1, 99);
System.out.println(list.get(1));

What is printed?

  • A

    30

  • B

    10

  • C

    20

  • D

    99

    check_circle

Explanation

set(1, 99) replaces the element at index 1 with 99. get(1) returns the new value 99.

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

Related questions