12:38 am - Monday August 21, 2017

Vector Example Program for clone()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

// Vector Example Program for clone()
/**
@author: candidjava.com
@description: The Program uses the clone() method to get a copy of an existing vector.
*/

import java.util.*;

class Clone {
public static void main(String[] args) {
Vector v1 = new Vector(3); // object v1 is created with size 3
// Add 3 numbers by using the add() method
v1.add(3);
v1.add(1);
v1.add(8);
System.out.println(v1);

Vector v2 = new Vector(3);
v2 = (Vector) v1.clone(); // Copy the data in obj v1 to obj v2 by using
// the clone method
System.out.println("The copy of the Vector is:    " + v2);
}
}


output:
[3, 1, 8]
The copy of the Vector is:    [3, 1, 8]

Filed in: Z-A All Java Codes

Comments are closed.