AP® Computer Science A

Free Version

Upgrade subject to access all content

Moderate

Adding to a List

APCSA-NOGBJX

Consider the following code segment.

ArrayList words = new ArrayList();
words.add("Hello");
words.add("Goodbye");
words.add("Hola");
words.add(2, "Adios");
for (String a : words)
          System.out.println(a);

What is printed as a result of executing the code segment?

A

Hello
Goodbye
Adios
Hola

B

Hello
Goodbye
Hola
Adios

C

Hola
Adios
Goodbye
Hello

D

Adios
Hola
Goodbye
Hello

E

Hello
Goodbye
Adios