Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 7: ArrayList
Start Practice TestPractice Test
About Exam
hard

Traversing and Modifying an ArrayList

Mark
< Prev
Next >

Consider the following instance variable and method.

private List<String> animals;

public void manipulate()
{
    for (int k = animals.size() - 1; k > 0; k--)
    {
        if (animals.get(k).substring(0, 1).equals("b"))
        {
            animals.add(animals.size() - k, animals.remove(k));
        }
    }
}

Assume that the animals list is initialized with the elements ["bear", "zebra", "bass", "cat", "koala", "baboon"]. What are the contents of animals after the manipulate method is executed?

A

[“bear”, “zebra”, “bass”, “cat”, “koala”, “baboon”]

B

[“baboon”, “bear”, “zebra”, “bass”, “cat”, “koala”]

C

[“zebra”, “cat”, “koala”, “baboon”, “bass”, “bear”]

D

[“baboon”, “zebra”, “bass”, “cat”, “bear”, “koala”]

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|