Here are 10 essential multiple-choice questions on Java ArrayList, covering key concepts.
Question 1
What is the default initial capacity of an ArrayList when it is created using the no-arg constructor?
Question 2
What will be the output of the following code?
import java.util.*;
public class Test {
public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
list.add(3);
list.remove(1);
System.out.println(list);
}
}
Question 4
What will be the result of the following code?
import java.util.*;
public class Test {
public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList<>();
list.add(10);
list.add(20);
list.add(30);
list.add(40);
list.set(2, 50);
System.out.println(list);
}
}
Question 6
What will be the output of the following code?
import java.util.*;
public class Test {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<>();
list.add("Apple");
list.add("Banana");
list.add("Cherry");
list.add("Date");
list.remove("Banana");
System.out.println(list);
}
}
Question 8
What will happen if you try to access an element with an index greater than the size of the ArrayList?
Question 9
What is the time complexity of the add() method in an ArrayList (amortized case)?
There are 10 questions to complete.
Quiz about Java ArrayList