Related Examples
  1. Vector class toString() method example
  2. Vector class toArray() method example
  3. Vector class subList(int fromIndex, int toIndex) method example
  4. Vector class size() method example
  5. Vector class setSize(int newSize) method example
  6. Vector class setElementAt(E obj, int index) method example
  7. Vector class set(int index, E element) method example
  8. Vector class retainAll(Collection c) method example
  9. Vector class removeElementAt(int index) method example
  10. Vector class removeElement(Object obj) method example
  11. Vector class removeAllElements() method example
  12. Vector class removeAll(Collection c) method example
  13. Vector class remove(Object o)method example
  14. Vector class remove(int index) method example
  15. Vector class lastIndexOf(Object o)method example
  16. Vector class lastElement() method example
  17. Vector class isEmpty()method example
  18. Vector class insertElementAt(E obj, int index)method example
  19. Vector class indexOf(Object o, int index)method example
  20. Vector class indexOf(Object o)method example
  21. Vector class hashCode()method example
  22. Vector class get(int index)method example
  23. Vector class firstElement()method example
  24. Vector class equals(Object o) method example
  25. Vector class ensureCapacity(int minCapacity)method example
  26. Vector class elements() method example
  27. Vector class copyInto(Object[] anArray)method example
  28. Vector class containsAll(Collection c)method example
  29. Vector class contains(Object o)method example
  30. Vector class clone()method example
  31. Vector class clear()method example
  32. Vector class capacity()method example
  33. Vector class addElement(E obj)method example
  34. Vector class addAll(int index, Collection c)method example
  35. Vector class addAll(Collection c)method example
  36. Vector class add(int index, E element) method example
  37. Vector class add(E e)method example
  38. Vector class trimToSize() method example
  39. Java Class Vector, Java Vector Methods, Java Vector Functions,Vector Examples Java

View All Examples
 

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

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US