ArrayList toArray Method Behavior
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]
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE