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)).
Please log in or register to report this question.