What does the following output?
List<Integer> v = new ArrayList<>(); v.add(3); v.add(2); v.add(1); v.remove(2); System.out.println(v);
This one is tricky.
There are two
remove() methods available on ArrayList.
One removes an element by index and takes an int parameter.
The other removes an element by value.
Due to the generics, it takes an Integer parameter in this example.
Since the int primitive is a better match, the element with index 2 is removed, which is the value of 1.
Option B is correct.