Limited access

Upgrade to access all content for this subject

Consider the following code segment.

ArrayList cities = new ArrayList();
cities.add("Atlanta");
cities.add("Boston");

for (int i = 1; i < cities.size(); i++)
   cities.add(i, "+");

System.out.println(cities);

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

A

[Atlanta, +, Boston]

B

[Atlanta, +, Boston, +]

C

No output because it is in an infinite loop.

D

[Atlanta, Boston, +]

E

[Atlanta, Boston]

Select an assignment template