Limited access

Upgrade to access all content for this subject

Which of the following methods would accept a list of pets and return a list that excludes birds?

The order of the pets in the resulting array list is unimportant. Assume that the description of a bird in the array list has the word “bird” in it.

I.

public static ArrayList<String> noBirdsI(ArrayList<String> petList)    
{
    ArrayList<String> petsNoBirds = new ArrayList<String>();

    for (String pet : petList) 
    {
        if (pet.indexOf("bird") < 0)
            petsNoBirds.add(pet);
    }
    return petsNoBirds;
}

II.

public static ArrayList<String> noBirdsII(ArrayList<String> petList)
{
    ArrayList<String> petsNoBirds = new ArrayList<String>();

    for (int i=0; i<petList.size(); i++)
    {
        if (petList.get(i).indexOf("bird") < 0)
            petsNoBirds.add(petList.get(i));
    }
    return petsNoBirds;
}

III.

public static ArrayList<String> noBirdsIII(ArrayList<String> petList)
{
    ArrayList<String> petsNoBirds = new ArrayList<String>();

    for (int i=petList.size()-1; i>=0; i--)
    {
        if (petList.get(i).indexOf("bird") < 0)
            petsNoBirds.add(petList.get(i));
    }
    return petsNoBirds;
}
A

I only.

B

II only.

C

III only.

D

I and II only.

E

I, II, and III.

Select an assignment template