ProgrammingHardTCS NQT Digital · Accenture Advanced

What is printed?

What is printed?
List<Integer> l = new ArrayList<>(List.of(10, 20, 30, 1));
l.remove(1);
l.remove(Integer.valueOf(1));
System.out.print(l);
  1. A. [10, 20, 30]
  2. B. [20, 30]
  3. C. [10, 30]
  4. D. [10, 20]

Correct answer: C. [10, 30]

remove(int) takes an index (removes 20); remove(Object) removes the element equal to 1.

More OOP with C++ and Java questions

Exams that ask this topic