Sail E0 Webinar
Question


What is the output of this program?


class Output {
public static void main(String args[]) {
ArrayList obj = new ArrayList();
obj.add("A");
obj.add("D");
obj.ensureCapacity(3);
obj.trimToSize();
System.out.println(obj.size());
}
}
Options:
A .  1
B .  2
C .  3
D .  4
Answer: Option B

trimTosize() is used to reduce the size of the array that underlines an ArrayList object.
Output:
$ javac Output.java
$ java Output
2



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers