Under the hood, ArrayList
is essentially a dynamic array. Every time you instantiate using new Arraylist<>()
what's happening is that an array is created to hold the values you want to store whose default capacity, not to be confused with size, is 10.
Every time you add a value that would increase the size beyond capacity a new array is created whose capacity is one more than 150% the previous capacity with the contents of the previous array copied within.
If you have a general idea what size the resulting list will be, or are certain but desire the flexibility afforded from using arraylists over arrays you can set the capacity to prevent this repetitive process of creating new arrays, copying the contents of the old array in the new one, and getting rid of the old one -- which will otherwise increase in occurrences proportional to the size of the list.