ArrayList Methods

AP Computer Science A· difficulty 2/5

ArrayList<String> list = new ArrayList<>();
boolean r = list.add("hello");
System.out.println(r + " " + list.size());

What is printed?

  • A

    true 1

    check_circle
  • B

    false 1

  • C

    true 0

  • D

    1 true

Explanation

ArrayList.add(E) always returns true and appends to the end, increasing size to 1.

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

Related questions