?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Difficult

Modifying ArrayList Based on Elements from Another ArrayList

APCSA-E61UED

What does list contain after this segment of code is executed?

ArrayList<Integer> list = new ArrayList<Integer>();
list.add(4);
list.add(6);
list.add(10);
list.add(2);
list.add(5);

ArrayList<Integer> p = new ArrayList<Integer>();
p.add(2);
p.add(1);
p.add(0);
p.add(4);
p.add(3);

for (int i=0; i<p.size(); i++)
{
    list.set(p.get(i), list.get(i)*p.get(i));
}
A

[8, 6, 0, 8, 15]

B

[0, 6, 8, 24, 8]

C

[20, 6, 0, 8, 6]

D

[4, 6, 10, 2, 5]

E

[0, 6, 20, 6, 20]