Check out example codes for "ArrayList trimToSize() method in java". It will help you in understanding the concepts better.

Code Example 1

import java.util.ArrayList;
public class TrimToSizeMethodJavaExample
{
   public static void main(String[] args)
   {
      // initially size of ArrayList is 10
      ArrayList<Integer> al = new ArrayList<Integer>(10);
      // adding integers to ArrayList using add() method
      al.add(1);
      al.add(3);
      al.add(5);
      al.add(9);
      al.add(11);
      al.add(14);
      // trims the size of ArrayList to 6 using trimToSize() method
      al.trimToSize();
      System.out.println("The ArrayList elements are: ");
      for(Integer number : al)
      {
         System.out.println("Number: " + number);
      }
   }
}

Learn ReactJs, React Native from akashmittal.com