Why is the default capacity of ArrayList 10?

The ArrayList is simple growing array. When trying to add element, and the buffer size is exceeded, it is simply growing. So the initial size can be any positive value.

The 1 would be too little. Even with a few elements we will have a few resize operations.

The 100 would be a loss of space.

So, the 10 is compromise. Why 10 and not 12 or 8? First hint, that the typical use cases were analysed and this is the best fit between lost of performance and lost of space. However, I think, seeing the Sun’s original code, that it wasn’t analysed so deeply and it is an arbitrary ‘not too small, not too big’ number.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)