?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Moderate

ArrayList Elements: Print First Characters of String Elements

APCSA-LZX1PY

Consider the following code.

List list = new ArrayList();
list.add("carrot");
list.add("potato");
list.add("milk");
for (int i=0; i<list.size(); i++)
{
    // put statement here
}

Which statement should be placed in the following for loop to print out the first character of each element stored in the ArrayList?

A
System.out.println(list.get(i).substring(0,1));
B
System.out.println(list.substring(0,1));
C
System.out.println(((String) list.get(i)).substring(0,1));
D
System.out.println(list.get(i).substring(i,i+1));
E
System.out.println(((String) list.get(i)).substring(i,i+1));