Home » JAVA Programming » Collections » Question
  1. What is the output of this program?
    import java.util.*;
    public class Output
    {
    public static void main(String args[])
    {
    ArrayList object = new ArrayList();
    object.add("Y");
    object.add("O");
    object.add("U");
    object.ensureCapacity(3);
    object.trimToSize();
    System.out.println(object.size());
    }
    }
    1. 0
    2. 1
    3. 2
    4. 3
    5. None of these
Correct Option: D

trimTosize() is used to reduce the size of the array that underlines an ArrayList object.



Your comments will be displayed only after manual approval.