AP® Computer Science A

Free Version

Upgrade subject to access all content

Moderate

ArrayList Removing String Elements and Printing Sports

APCSA-YGFGPV

Consider the follow section of code.

ArrayList<String> sports;
sports = new ArrayList<String>();
sports.add("football");
sports.add("soccer");
sports.add("baseball");
sports.add("basketball");
sports.add("golf");

for(int i=0; i< sports.size(); i++)
{
     if(sports.get(i).indexOf(“ball”) >= 0)
     {
          sports.remove(i);
     }
}
System.out.println(sports);

What is the output?

A

[football, baseball, basketball]

B

[soccer, basketball, golf]

C

[soccer, golf]

D

[football, soccer, baseball, basketball, golf]

E

[ ]