Limited access

Upgrade to access all content for this subject

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));
Select an assignment template