What is the difference between ArrayList al = new ArrayList(); and ArrayList al = new ArrayList(0)?
3 Answers
ArrayList(0)
Empty list with the specified initial capacity. Hense none for 0
ArrayList()
Empty list with an initial capacity of ten.
Please read the following: http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html
Comments
If you look on the API, it says, ArrayList() - Constructs an empty list with an initial capacity of ten.
ArrayList(int initialCapacity) - Constructs an empty list with the specified initial capacity.
1 Comment
Lovis
in (open) JDK8, this seems to be not the case. It does say that it creates an initial capacity of 10, but in fact it creates a capacity of 0: grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/…
new ArrayList()is equivalent to (and probably implemented in terms of)new ArrayList(10)