Online Java Compiler By
JavaTpoint.com
import java.util.*; public class HashSetCloneExample1 { public static void main(String[] args) { //Creating HashSet HashSet
set = new HashSet
(); //Add elements into the Set set.add("JavaTpoint"); set.add("Google"); set.add("Hindi100"); set.add("101"); set.add("Facebook"); //Print the elements System.out.println("HashSet elements: " + set); //Creating a new cloned set HashSet
clonedSet = new HashSet
(); //Clone the HashSet clonedSet = (HashSet)set.clone(); //Displaying the new Set after Cloning; System.out.println("The new clone set elements: " + clonedSet); } }
Output