?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Moderate

Adjusting Elements in an ArrayList

APCSA-NJPEEE

Consider the following method.

public static void listAdjustments(ArrayList list)
{
    for (int i=0; i<list.size(); i++)
    {
        if (list.get(i) instanceof Integer | | list.get(i) instanceof Double)
            list.set(i, list.get(i)+"");
        else
        if (!(list.get(i) instanceof String)) 
            list.set(i, list.get(i)+"");
     }
 }

Consider the following code from the main method.

ArrayList list = // a list of Objects
listAdjustments(list);

Which one of the following statements is true about list after this method is called?

A

All elements in list will remain unchanged.

B

Every element in list will be a String.

C

Executing the command System.out.println(list); before calling the method and then executing it again after calling the method will result in different output.

D

The data types at each position in list will be the same before and after calling the method.

E

This method will produce a data type conversion error when called.