Java ArrayList.ensureCapacity(int minCapacity)

Syntax

ArrayList.ensureCapacity(int minCapacity) has the following syntax.

public void ensureCapacity(int minCapacity)

Example

In the following code shows how to use ArrayList.ensureCapacity(int minCapacity) method.


//from w ww  . ja  v a2 s . co m

import java.util.ArrayList;

public class Main {
  public static void main(String args[]) {

    ArrayList<Integer>  arrlist = new ArrayList<Integer> (5);

    arrlist.add(10);
    arrlist.add(50);
    arrlist.add(30);
  
    arrlist.ensureCapacity(5000);

  }
}