The capacity is the number of elements the array list can hold before the internal data structure has to resize.
Use the ensureCapacity() method to check that the internal data structure has enough capacity before adding elements:
public void ensureCapacity(int minimumCapacity)
import java.util.ArrayList; public class MainClass { public static void main(String[] a) { ArrayList list = new ArrayList(); list.add("A"); list.ensureCapacity(10); System.out.println(list.size()); } }
1