Discussion
What will be the output of the program?
import java.util.*;
public class Sample01
{
public static void main(String[] args)
{
List<Integer> nums = new ArrayList<Integer>();
nums.add(10); nums.add(20); nums.add(30);
nums.remove(1);
System.out.println(nums);
}
}
Answer: A
There are two remove methods and the int literal 1 selects remove(int index), not remove(Object). The element at index 1 is 20, so it is taken out and the list becomes [10, 30]. Removing the VALUE 1 would have needed nums.remove(Integer.valueOf(1)).
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