-
What is the output of this program?
import java.util.*;
public class Result
{
public static void main(String args[])
{
ArrayList object = new ArrayList();
object.add("Y");
object.add("O");
object.add("U");
object.ensureCapacity(5);
System.out.println(object.size());
}
}
-
- 3
- 2
- 6
- 0
- Any Garbage Value
Correct Option: A
Although object.ensureCapacity(5); has manually increased the capacity of object to 5 but the value is stored only at index 3, therefore object.size() returns the total number of elements stored in the object i:e 3, it has nothing to do with ensureCapacity().