Vector class ensureCapacity(int minCapacity)method example
Increases the capacity of this vector
Vector class ensureCapacity(int minCapacity)method example. This example shows you how to use ensureCapacity(int minCapacity)method.This method Increases the capacity of this vector, if necessary, to ensure that it can hold at least the number of components specified by the minimum capacity argument.
Here is the code:-
/*
* @Program that Increases the capacity of this vector
* EnsureCapacity.java
* Author:-RoseIndia Team
* Date:-24-May-2008
*/
import java.util.*;
public class EnsureCapacity {
public static void main(String[] args) {
//creating a vector
Vector v=new Vector();
v.add("Tikil");
v.add("Deepu");
// Returns the current capacity of this vector.
int i=v.capacity();
System.out.println("Capacity of the vector "+i);
//Increases the capacity of this vector
v.ensureCapacity(20);
//displays the new capacity of the vector
System.out.println("New Capacity of the vector "+v.capacity());
}
} |
Output of the program:
Capacity of the vector 10
New Capacity of the vector 20 |
|