Click here to watch in Youtube : https://www.youtube.com/watch?v=tKXaem3GFWc&list=UUhwKlOVR041tngjerWxVccwVectorExample.java import java.util.Vector;
/*
* Example of Vector(int initialCapacity, int capacityIncrement) constructor.
*/
public class VectorExample
{
public static void main( String[] args )
{
Vector<String> vector = new Vector<String>(5, 2);
vector.add("Dave");
vector.add("Peter");
vector.add("Phil");
vector.add("Rohit");
vector.add("Virat");
System.out.println("vector : " + vector);
System.out.println("vector size: " + vector.size());
System.out.println("vector capacity: " + vector.capacity() + "\n");
vector.add("Raj");
System.out.println("vector : " + vector);
System.out.println("vector size: " + vector.size());
System.out.println("vector capacity: " + vector.capacity() + "\n");
}
}
Output vector : [Dave, Peter, Phil, Rohit, Virat]
vector size: 5
vector capacity: 5
vector : [Dave, Peter, Phil, Rohit, Virat, Raj]
vector size: 6
vector capacity: 7