Hello,
I read:
The default initial capacity of an ArrayList is pretty small (10 from Java 1.4 - 1.7). But since the underlying implementation is an array, the array must be resized if you add a lot of elements. To avoid the high cost of resizing when you know you're going to add a lot of elements, construct the ArrayList with a higher initial capacity.
For checking this I developed this
test. Where I create two ArraList objects. First one with default initial capacity (10) and the other with the number of elements I will add (LIMIT_1). Also I test the time that requiere each adding.
Here the output:
The results are on the contrary I expected. The one with resizing is slower.
Any suggestion?
Thanks,
My certifications: OCJP6, OCJP8
Working on my next goal: Oracle Certified Expert, EE 6 Java Persistence API Developer