Here are 10 essential multiple-choice questions on Java List Interface, covering key concepts.
Question 2
What is the default initial capacity of an ArrayList when created with a no-arg constructor?
Question 3
What will be the output of the following code?
import java.util.*;
public class Test {
public static void main(String[] args) {
List<Integer> list = new ArrayList<>();
list.add(1); list.add(2); list.add(3);
list.add(1, 10);
System.out.println(list);
}
}
Question 4
Which List implementation provides the best performance for random access operations?
Question 6
What will be the output of the following code?
import java.util.*;
public class Test {
public static void main(String[] args) {
List<Integer> list = new LinkedList<>();
list.add(10);
list.add(20);
list.remove(0);
System.out.println(list);
}
}
Question 7
What is the time complexity of ArrayList.add(index, element) operation in the worst case?
Question 10
What will be the output of the following code?
import java.util.*;
public class Test {
public static void main(String[] args) {
List<String> list = Arrays.asList("A", "B", "C");
list.add("D");
System.out.println(list);
}
}
There are 10 questions to complete.
Quiz about Java List Interface