If we do ArrayList lst = new ArrayList(); What is the initial capacity of the ArrayList lst ?
-
8
-
10
-
none
-
0
When you create an ArrayList using the no-argument constructor new ArrayList(), Java initializes it with a default capacity of 10. This is an implementation detail of the ArrayList class designed to balance memory usage and performance for common use cases. The capacity is not 0, 8, or unlimited.
For the classic teaching answer (and true for Java 6/7), calling new ArrayList() with no argument constructor creates a backing array with an initial capacity of 10 — this is the commonly quoted default capacity in Java documentation and most textbooks/courses. This matches the marked answer. Note that in Java 8+, the JVM actually lazily initializes an empty backing array (capacity 0) until the first element is added, at which point it grows to capacity 10 — so strictly on newer JDKs the "initial" capacity before any add is 0, not 10. Since most quiz contexts and Java documentation reference "10" as the default ArrayList capacity, 10 is treated as correct here, though the Java 8+ lazy-init nuance means the question is version-dependent.