Tuesday 6 May 2014

Vector : clone : Clone the Vector

public synchronized Object clone()
Returns a clone of this vector.

import java.util.*;

class VectorClone{
 public static void main(String args[]){
  Vector<Integer> myVector1;
  Object myVector2;
  
  myVector1 = new Vector<> ();
  myVector2 = new Vector<> ();
  
  /* Add Elements to myVector1 */
  for(int i=1; i < 6; i++)
   myVector1.addElement(i);
   
  System.out.println("Elements in myVector1 are");
  System.out.println(myVector1);
  
  System.out.println("\nCloning myVector1 to myVector2");
  
  myVector2 = myVector1.clone();
  
  System.out.println("\nElements in myVector2 are");
  System.out.println(myVector2);
 }
}


Output
Elements in myVector1 are
[1, 2, 3, 4, 5]

Cloning myVector1 to myVector2

Elements in myVector2 are
[1, 2, 3, 4, 5]


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment