Limited access

Upgrade to access all content for this subject

Consider the following method.

public static ArrayList<String> rearrangeList(ArrayList<String> words)
{
    ArrayList<String> outputList = new ArrayList<String>();
    for (int i=0; i<words.size(); i++)
    {
        if (i%2==1)
            outputList.add(0, words.get(i));
        else
            outputList.add(words.get(i));
    }
    return outputList;
}

What is the output after running the following section of code?

ArrayList<String> wordList = new ArrayList();
wordList.add("hard");
wordList.add("work");
wordList.add("pays");
wordList.add("off");

// rearrangeList called twice below
System.out.println(rearrangeList(rearrangeList(wordList)));
A
[hard, work, pays, off]
B
[pays, work, off, hard]
C
[off, work, hard, pays]
D
[off, pays, work, hard]
E
[off, off, off, off]
Select an assignment template