Developing Algorithms Using ArrayLists

AP Computer Science A· difficulty 2/5

int[] arr = {3, 1, 4, 1, 5};
ArrayList<Integer> list = new ArrayList<>();
for (int x : arr) list.add(x);
System.out.println(list.size());

What is printed?

  • A

    0

  • B

    4

  • C

    3

  • D

    5

    check_circle

Explanation

Each of the 5 elements is added to the list, so size is 5.

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

Related questions

AP Computer Science A · Developing Algorithms Using ArrayLists Practice Question | Acemy