import java.util.*;
public class TrimToSizeArrayList {
public static void main(String[] args) {
ArrayList<String> al = new ArrayList<>();
al.add("Ajay");
al.add("Vijay");
al.add("Krishna");
al.add("Kiyan");
al.add("Nishu");
//this method will trim the capacity of array list
//to the current size of the given Array
al.trimToSize();
Iterator itr = list.iterator();
while (itr.hasNext()) {
System.out.println(itr.next() + " ");
}
}
}