Limited access

Upgrade to access all content for this subject

Consider the following method.

public static ArrayList createColorList(ArrayList<Integer> nums, ArrayList<String> colors)
{
    ArrayList colorList = new ArrayList()
    for (int i=0; i<nums.size(); i++)
    {
        colorList.add(nums.get(i));
        for (int j=0; j<nums.get(i); j++)
        {
            colorList.add(colors.get(j));
        }
    }
    return colorList;
 }    

What will be contained in colorList after the following segment of code from the same class is executed?

ArrayList<Integer> nums = new ArrayList<Integer>();
nums.add(2);
nums.add(1);
nums.add(3);
ArrayList<String> colors = new ArrayList<String>();
colors.add("green");
colors.add("yellow");
colors.add("black");
colors.add("red");
colors.add("brown");
colors.add("white");
ArrayList colorList = createColorList(nums, colors);
A
[2, green, yellow, 1, black, 3, red, brown, white]
B
[2, green, 2, yellow, 1, green, 3, green, 3, yellow, 3, black]
C
[2, green, 2, yellow, 1, black, 3, red, 3, brown, 3, white]
D
[2, black, 1, yellow, 3, red]
E
[2, green, yellow, 1, green, 3, green, yellow, black]
Select an assignment template