?

Free Version

Upgrade subject to access all content

Moderate

Counting the Removes in an ArrayList of Strings

APCSA-VTW1VX

Consider the following method.

public static ArrayList<String> removeBirds(ArrayList<String> animals)
{
     for(int i=0; i<animals.size(); i++)
     {
          if(animals.get(i).indexOf("bird") >= 0)
          {
               animals.remove(i);
          }
     }
     return animals;
}

If the following array list were passed to this method, how many elements would it contain after the method completed execution?

["collie", "bluebird", "blackbird", "lion", "cardinal", "hummingbird",
"snowbird"]
A

3

B

4

C

5

D

6

E

7