Java ArrayList(int initialCapacity) Constructor

Syntax

ArrayList(int initialCapacity) constructor from ArrayList has the following syntax.

public ArrayList(int initialCapacity)

Example

In the following code shows how to use ArrayList.ArrayList(int initialCapacity) constructor.


/*from   w  ww . j ava  2s.c o  m*/
import java.util.ArrayList;

public class Main {
  public static void main(String args[]) {
    ArrayList<Integer>  arrlist = new ArrayList<Integer> (10);
  
    arrlist.add(1);
    arrlist.add(2);
    arrlist.add(3);
    arrlist.add(4);
    arrlist.add(5);

    System.out.println(arrlist);


  }
}

The code above generates the following result.