Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load factor of Arraylist and Vector?

Hi I was trying to find the load factor of Array list and vector but I was not able to find it. I know load factor of HashMap and other Map is 0.75. Can any one help to find me how to check the load factor of Vector and Arraylist.

like image 271
Som Avatar asked Oct 18 '25 15:10

Som


2 Answers

ArrayList:

  • Initial Capacity:10
  • Load Factor:1 (when the list is full)
  • Growth Rate: current_size + current_size/2

Vector:

  • Initial Capacity:10
  • Load Factor:1 (when the list is full)
  • Growth Rate: current_size * 2 (if capacityIncrement is not defined) current_size + capacityIncrement (if capacityIncrement is defined during vector initialization)
like image 112
Vivek Goel Avatar answered Oct 20 '25 05:10

Vivek Goel


I assume you would like to know how ArrayList and Vector increase its size.

For ArrayList, every time you put an element into it, it will check if the nested array needs to be enlarge its size. If yes, generally, its size will grow with:

newCapacity = oldCapacity + (oldCapacity >> 1);

For some special case, for example, add many or huge number of elements, things will be different. Please refer grow(int minCapacity) function in java.util.ArrayList source code.

Regarding Vector, generally, its size will grow with:

newCapacity = oldCapacity + ((capacityIncrement > 0) ?
                                         capacityIncrement : oldCapacity);

For some special cases, please refer grow(int minCapacity) in java.util.Vector.

like image 25
Sid Zhang Avatar answered Oct 20 '25 04:10

Sid Zhang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!