Traversing ArrayLists

AP Computer Science A· difficulty 2/5

public static int sum(ArrayList<Integer> list) {
    int total = 0;
    for (int i = 0; i < /* missing */; i++) {
        total += list.get(i);
    }
    return total;
}

Which expression correctly replaces /* missing */?

  • A

    list.size

  • B

    list.size()

    check_circle
  • C

    list.length()

  • D

    list.length

Explanation

ArrayList uses size(), a method call. length is a property of arrays, and length() applies to Strings.

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

Related questions