Question 1
What is the default initial capacity of an ArrayList when it is created using the no-arg constructor?
5
10
20
1
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); } }
[1, 3]
[2, 3]
[1, 2]
[1, 2, 3]
Question 3
Which method of ArrayList is used to add an element at a specific index?
addAtIndex()
insert()
add()
add(index, element)
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); } }
[10, 20, 50, 40]
[10, 20, 30, 40]
[10, 20, 40, 50]
[50, 20, 30, 40]
Question 5
Which of the following methods is used to check if an ArrayList is empty?
isEmptyList()
isNull()
isEmpty()
empty()
Question 6
Which of the following methods returns the number of elements in an ArrayList?
size()
length()
count()
getSize()
Question 7
What is the time complexity of the add() method in an ArrayList (amortized case)?
O(1)
O(n)
O(log n)
O(n^2)
There are 7 questions to complete.