Discussion
Which line contains the error?
import java.util.*;
public class Sample57
{
public static void main(String[] args)
{
List<String> ro = Collections.unmodifiableList(new ArrayList<String>());
assert ro.isEmpty();
ro.add("x");
System.out.println(ro.size());
}
}
Answer: A
An unmodifiable view rejects every mutation with UnsupportedOperationException, so the add is the error. The assertion above it is correct and passes. Note the wrapper is a view, not a copy: changes made through the original list would still be visible here.
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