?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Difficult

ArrayList methods

APCSA-NWLJLV

Consider the following code.

ArrayList<String> list = new ArrayList<String>();
list.add("hi");
list.add("bye");
list.add("hi");
list.add("hi");
list.add("bye");
for (int i = 0; i < list.size(); i++)
 {
    if (list.get(i).equals("hi"))
      list.remove(i);
    else
      list.set(i, "see ya");
 }
 System.out.println(list);

What is printed as a result of executing this code?

A

[bye, bye]

B

[hi, bye, hi, hi, bye]

C

[see ya, see ya]

D

[bye, hi, see ya]

E

[see ya]