Saturday 13 December 2014

Java : Collection Framework : Vector (Capacity Increment)


Click here to watch in Youtube : 
https://www.youtube.com/watch?v=tKXaem3GFWc&list=UUhwKlOVR041tngjerWxVccw

VectorExample.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


To Download VectorDemoCapacityIncrement Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/VectorDemoCapacityIncrement.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • No comments:

    Post a Comment