Limited access

Upgrade to access all content for this subject

Consider the following method.

public static ArrayList methodA(ArrayList<String> list)
{
    for(int i=0; i<list.size(); i++)
    {
        if(list.get(i).substring(list.get(i).length()-2).indexOf("s")<0)
        {
            list.remove(i);
            i--;
        }
        else
            list.set(i, list.get(i).substring(0, list.get(i).length()-2));
     }
     return list;
}

Which of the following situations would always cause this method to throw an error?

A

list contains two elements in a row that have an "s" in their next-to-last positions.

B

list contains no elements.

C

list contains a string that is only one character long.

D

The last element in list ends with an "s".

E

list does not contain any elements that have an "s" in their next-to-last position.

Select an assignment template