What is the difference between ArrayList al = new ArrayList (); and ArrayList al = new ArrayList (0)?

What is the difference between ArrayList al = new ArrayList (); and ArrayList al = new ArrayList (0)?

+2
source share
3 answers

If you look at the API , it says: ArrayList () - Creates an empty list with an initial capacity of ten.

ArrayList (int initialCapacity) - Creates an empty list with the specified initial capacity.

+5
source
ArrayList(0) 

An empty list with the specified initial capacity. It does not matter for 0

 ArrayList() 

An empty list with an initial capacity of ten.

Please read the following: http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html

+6
source

new ArrayList () gives you a list of arrays with default bootstrap (how much memory was originally allocated from ArrayList). new ArrayList (0) gives you a list of arrays with zero initial capacity. As soon as an item is added to the list, capacity is allocated.

+1
source

Source: https://habr.com/ru/post/1212706/


All Articles