1.

What Is The Output Of This Program? 1. Import Java.util.*; 2. Class Output { 3. Public Static Void Main(string Args[]) { 4. Arraylist Obj = New Arraylist(); 5. Obj.add("a"); 6. Obj.ensurecapacity(3); 7. System.out.println(obj.size()); 8. } 9. }

Answer»

ALTHOUGH OBJ.ensureCapacity(3); has manually increased the capacity of obj to 3 but the value is stored only at index 0, therefore obj.size() returns the total number of elements stored in the obj i:e 1, it has NOTHING to do with ensureCapacity().

Output:

$ javac Output.java
$ java Output
1

Although obj.ensureCapacity(3); has manually increased the capacity of obj to 3 but the value is stored only at index 0, therefore obj.size() returns the total number of elements stored in the obj i:e 1, it has nothing to do with ensureCapacity().

Output:

$ javac Output.java
$ java Output
1



Discussion

No Comment Found

Related InterviewSolutions