How to trim the capacity of an ArrayList?
For minimizing the storage used by an
ArrayList to the number of it's elements we can use the
ArrayList.trimToSize() method call. In the code below we create an instance of
ArrayList with the initial capacity set to 100. Later we only add five data into the list. To make the capacity of the
ArrayList minimized we call the