Click here to watch in Youtube :
https://www.youtube.com/watch?v=86ewQZYu3n8&list=UUhwKlOVR041tngjerWxVccw
HashSetExample.java
Output
https://www.youtube.com/watch?v=86ewQZYu3n8&list=UUhwKlOVR041tngjerWxVccw
HashSetExample.java
import java.util.HashSet; /* * Example of clone() method. */ public class HashSetExample { public static void main( String[] args ) { HashSet<String> hashSet = new HashSet<String>(); hashSet.add("Dave"); hashSet.add("Peter"); hashSet.add("Phil"); hashSet.add("Rohit"); hashSet.add("Virat"); System.out.println("hashSet: " + hashSet + "\n"); /* * Returns a shallow copy of this HashSet instance: the elements * themselves are not cloned. */ HashSet<String> clonedHashSet = (HashSet<String>) hashSet.clone(); System.out.println("clonedHashSet : " + clonedHashSet); } }
hashSet: [Rohit, Dave, Phil, Peter, Virat] clonedHashSet : [Rohit, Peter, Virat, Dave, Phil]
https://sites.google.com/site/javaee4321/java-collections/HashSetDemoClone.zip?attredirects=0&d=1
See also:
No comments:
Post a Comment