Java ArrayList trimToSize() Method
trimToSize() method is used for memory optimization. It trims the capacity of ArrayList to the current list size.
public void trimToSize()
Given arraylist is having capacity of 10 but there are only 3 elements in it, calling trimToSize() method on this ArrayList would change the capacity from 10 to 3.