Introduction
In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..
import java.util.ArrayList; import java.util.Collections; public class Javacollectionexcercise { public static void main(String[] args) { ArrayList<String> Stringslist= new ArrayList<String>(3); Stringslist.add("Audi"); Stringslist.add("BMW"); Stringslist.add("Bugatti"); System.out.println("Original array list: " + Stringslist); //Increase capacity to 7 Stringslist.ensureCapacity(7); Stringslist.add("Ford"); Stringslist.add("Honda"); Stringslist.add("Hyundai"); Stringslist.add("Ferrari"); System.out.println("New Increased array list: " + Stringslist); } }