210k views
1 vote
Consider the following scenario. The Current State of One Particular ArrayList The capacity of a particular ArrayList is five (5) at some point in time. At that same time, there happens to be four (4) elements of client data in the list. The Next Operation Requested of this ArrayList From that state, a client requests to add) 25 data items to the list The Internal Reaction of the ArrayList This will certainly require an increase in the list's capacity. The question is about what actually happens internally in the time interval during which all of these twenty-five 25 add)s are executed. a. There will be no calls to ensureCapacity().b. There will be one call to ensureCapacity.c. There will be three calls to ensureCapacityd. There will be five calls to ensureCapacity).

User Ryan Jay
by
5.7k points

1 Answer

2 votes

Answer:

The ArrayList initial functionality is 5, there were 4 components.

Then, add 25 more elements by using add()calling 25 times So total number of elements after the completed operation would be 4 + 25= 29.

5th component will be introduced without calling ensureCapacity(); while adding 6th element-> ensureCapacity(2* 5+ 1) it will call, making the capacity 11.

So ArrayList's capacity will be 11.

Next 7th to 11th components will also be added automatically once the 12th element is added, it will name ensureCapacity(2* 11+ 1) and make the capacity 23.

While adding 24th dimension, ensureCapacity(2* 23+ 1) will be called again and this will make the capacity 47.

There will therefore be 3 (three) calls to ensure the feature Ability).

Elements of Rest 25th to 29th will be added seamlessly as ability becomes 47.

User RedDwarfian
by
5.8k points