Tuesday, 9 December 2014

Java : Collection Framework : Vector (Clone)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=4ZMl-P3AQ4w&list=UUhwKlOVR041tngjerWxVccw

VectorExample.java
import java.util.Vector;

/*
 *  Example of clone() method 
 */
public class VectorExample
{

    public static void main( String[] args )
    {
        Vector<Integer> vector = new Vector<Integer>();

        vector.add(10);
        vector.add(20);
        vector.add(30);

        System.out.println("vector  : " + vector);

        /*
         * Returns a clone of this vector. The copy will contain a reference to
         * a clone of the internal data array, not a reference to the original
         * internal data array of this Vector object.
         */
        Object object = vector.clone();
        Vector<Integer> clonedVector = (Vector<Integer>) object;

        System.out.println("clonedVector  : " + clonedVector);

    }
}

Output
vector  : [10, 20, 30]
clonedVector  : [10, 20, 30]

To Download VectorDemoClone Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/VectorDemoClone.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