public void trimToSize()
The trimToSize() method makes sure that there is no unused space in the internal data structure.
import java.util.ArrayList; public class MainClass { public static void main(String[] a) { ArrayList list = new ArrayList(); list.add("A"); list.ensureCapacity(10); list.trimToSize(); } }