| preferred AP College board partner for AP classes
AP Computer Science A/Unit 7: ArrayList
Start Practice TestPractice Test
About Exam
medium
ArrayList toArray Method Behavior
< Prev
Next >

Consider the following code segment. What is printed when it is executed?

import java.util.ArrayList;
public class ToArrayTest {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("Red");
        list.add("Green");
        list.add("Blue");
        Object[] arr = list.toArray();
        arr[1] = "Yellow";
        System.out.println(list);
    }
}
A

[Yellow, Green, Blue]

B

[Red, Green, Blue]

C

[Red, Green, Blue, Yellow]

D

[Red, Yellow, Blue]

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