Java ArrayList containsensureCapacity Example
ArrayList class containsensureCapacity method example. This example shows you how to use containsensureCapacity method.
ArrayList class containsensureCapacity method example.public void ensureCapacity(int minCapacity) Increases the capacity of this ArrayList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.
Here is the output
/**
* @ # EnsureCapacity.java
* A class repersenting use to ensureCapacity method of ArrayList class in java.util package
* version 14 May 2008
* author Rose India
*/
import java.util.*;
public class EnsureCapacity {
public static void main(String args[]) {
ArrayList arrlist = new ArrayList(0);
int i = 0;
String str = "Rose India";
//Add the specified element to the end of this list.
arrlist.add(0, "ra");
arrlist.add(str);
// Increases the capacity
arrlist.ensureCapacity(10);
System.out.println("Increases the capacity ");
}
} |
|