In the JDK 1.7 into the ArrayList.java the method ensureCapacity
increments the array capacity using the following expression: int newCapacity = oldCapacity + (oldCapacity >> 1)
so it seems that the new capacity will be almost the 50% more than the old.
However in many books is said that the capacity is doubled... so the books aren't updated or I don't understand well?
You're understanding is correct, newCapacity is 50% more than oldCapacity
In Java 6 newCapacity is calculated as
int newCapacity = (oldCapacity * 3)/2 + 1;
This is the beauty of an open source language such as Java, you can see the implementation - if it doesn't fit your requirements, you can implement your own.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With