| 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
< 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

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

B

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

C

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

D

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

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.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy