Limited access

Upgrade to access all content for this subject

Consider the following code segment.

ArrayList< String > sports;
sports = new ArrayList< String >();
sports.add("football");
sports.add("soccer");
sports.add("baseball");
sports.add("basketball");
sports.add("golf");
int i = sports.size()-1;

for(String sport : sports)
{
     if(sport.indexOf("ball") >= 0)
     {
          sports.remove(i);
          i--;
     }
     i++;
}
System.out.println(sports);

What is printed as a result of executing the code segment?

A

[football, baseball, basketball]

B

[soccer, basketball, golf]

C

[soccer, golf]

D

[football, soccer, baseball, basketball, golf]

E

An error occurs.

Select an assignment template