Clone a hash set
Object clone()
- Returns a shallow copy of this HashSet instance: the elements themselves are not cloned.
import java.util.HashSet;
public class Main{
public static void main(String args[]) {
HashSet<String> hs = new HashSet<String>();
hs.add("java2s.com");
hs.add("A");
hs.add("D");
hs.add("E");
hs.add("C");
hs.add("j a v a2s.com");
System.out.println(hs);
Object obj = hs.clone();
System.out.println(obj);
}
}
The output:
[D, E, j a v a2s.com, A, java2s.com, C]
[D, E, j a v a2s.com, java2s.com, A, C]