Discussion
What will be the output of the program?
import java.util.*;
public class Item22
{
public static void main(String[] args)
{
Integer[] boxed = {10, 20, 30};
List<Integer> view = Arrays.asList(boxed);
boxed[0] = 99;
System.out.println(view.size() + " " + view.get(0));
}
}
Answer: B
An Integer[] is an array of references, so varargs spreads it and the list holds three elements, unlike the int[] case where the whole array arrives as one object. The list is also a VIEW over that array, not a copy, so writing to the array afterwards is visible through it and the first element reads 99.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development