4:32 pm - Saturday September 23, 2017

HashSet example program for Object 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
/**

 *@author:candidjava.com
 *@description:Hashset example program for Object Clone()

 */
import java.util.HashSet;

public class HashSetClone {
	public static void main(String args[]) {

		HashSet newset = new HashSet(); // creating two hash sets
		HashSet cloneset = new HashSet();

		newset.add("Kingsley");
		newset.add("Ram"); // adding hashset values
		newset.add("Pradeep");

		cloneset = (HashSet) newset.clone(); // cloning the hash set

		System.out.println("Hash set values: " + newset);
		System.out.println("Cloned Hash set values: " + cloneset);
	}
}

Output

Hash set values: [Kingsley, Ram, Pradeep]
Cloned Hash set values: [Kingsley, Ram, Pradeep]

BACK

Filed in: Z-A All Java Codes

Comments are closed.