hashset object clone 28 29 method in java

Solutions on MaxInterview for hashset object clone 28 29 method in java by the best coders in the world

showing results for - "hashset object clone 28 29 method in java"
Violeta
26 Jun 2017
1import java.util.HashSet;
2public class HashSetObjectCloneMethodExample
3{
4   public static void main(String[] args)
5   {
6      HashSet<String> hs = new HashSet<String>();
7      hs.add("Welcome");
8      hs.add("hello");
9      hs.add("world");
10      hs.add("core");
11      hs.add("java");
12      System.out.println("HashSet before using clone() method: " + hs);
13      // create new cloned HashSet
14      HashSet<String> objClone = new HashSet<String>();
15      // clone HashSet using clone() method
16      objClone = (HashSet)hs.clone();
17      // print new HashSet after cloning
18      System.out.println("HashSet after using clone() method: " + objClone);
19   }
20}