clone hashset java code example
Example: HashSet Object clone() method in java
import java.util.HashSet;
public class HashSetObjectCloneMethodExample
{
public static void main(String[] args)
{
HashSet<String> hs = new HashSet<String>();
hs.add("Welcome");
hs.add("hello");
hs.add("world");
hs.add("core");
hs.add("java");
System.out.println("HashSet before using clone() method: " + hs);
HashSet<String> objClone = new HashSet<String>();
objClone = (HashSet)hs.clone();
System.out.println("HashSet after using clone() method: " + objClone);
}
}