Introduction to ArrayList

AP Computer Science A· difficulty 2/5

ArrayList<Integer> list = new ArrayList<>();
list.add(7);
list.add(8);
int x = list.get(0) + list.get(1);
System.out.println(x);

What is printed?

  • A

    Compile-time error

  • B

    7

  • C

    15

    check_circle
  • D

    78

Explanation

Autoboxing converts int 7 and 8 into Integer objects when added. Auto-unboxing converts them back to int when adding, producing 15.

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

Related questions