Question
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());
}
}
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());
}
}
Answer: Option B
Was this answer helpful ?
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 ?
Submit Solution