3:32 pm - Sunday August 20, 2017

Create a copy of Hashset 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

This tutorial explains how to Create a copy of Hashset using Object clone() method.

Returns a shallow copy of this HashSet instance: the elements themselves are not cloned.

 To get absolute copy of data from one hash variable to another variable.

Example

import java.util.HashSet; 

public class CloneElements

{

   public static void main(String a[])

      {             

       HashSet <String> newset = new HashSet <String>();

       HashSet <String> cc = new HashSet <String>();            

       newset.add("Learning");

       newset.add("Easy");

       newset.add("Simply");  

       cc=(HashSet)newset.clone();

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

       System.out.println("Clone Hash set values: "+ cc);          
     }

}

Output

         Hash set values: [Learning, Simply, Easy]

         Clone Hash set values: [Learning, Simply, Easy]

BACK

Filed in: Java Examples

Comments are closed.