Limited access

Upgrade to access all content for this subject

Consider the following method.

public static Object listString(ArrayList list)
{
    int count=0;
    for (int i=list.size()-1; i>=0; i--)
    {
        if (list.get(i) instanceof String)
        {
            if (((String) list.get(i)).length()<10)
            {
                if (count==1) 
                    return list.get(i);
                count++;
            }
        }
   {
   return null;
}

Given the following code from the main method:

ArrayList list = // a list of Objects
Object o = listString(list);

Which of the following BEST describes what listString will return if it reaches the return statement in the loop?

A

The last String in the list that is less than 10 characters long.

B

The count of the number of Strings in the list.

C

The first String in the list that is less than 10 characters long.

D

The next-to-last String in the list that is less than 10 characters long.

E

The second String in the list that is less than 10 characters long.

Select an assignment template