12:50 am - Thursday July 27, 2017

Create duplicate of LinkedHashSet using 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

BACK

                                The method public Object clone () displays the copy of the elements present in the linkedhashset.The cloned set looks same as that of the actual set.The elements themselves are not cloned.

Example Program


import java.util.LinkedHashSet;

public class LinkedHashSetClone

{

	public static void main(String args[])

	{

		LinkedHashSet lh = new LinkedHashSet();

		lh.add("Add");

		lh.add("Sub");

		lh.add("Mul");

		LinkedHashSet lhh = new LinkedHashSet();

		lhh = (LinkedHashSet) lh.clone();

		System.out.println("The set is: " + lh);

		System.out.println("Cloned set is: " + lhh);

	}

}

Output

   The set is: [Add, Sub, Mul]

   Cloned set is: [Add, Sub, Mul]

BACK

Filed in: Java Examples

Comments are closed.