Click here to watch in Youtube :
https://www.youtube.com/watch?v=nNYlGpUbKs8&list=UUhwKlOVR041tngjerWxVccw
HashSetExample.java
Output
https://www.youtube.com/watch?v=nNYlGpUbKs8&list=UUhwKlOVR041tngjerWxVccw
HashSetExample.java
import java.util.ArrayList; import java.util.HashSet; /* * Example of addAll(Collection<? extends E> c) method. */ public class HashSetExample { public static void main( String[] args ) { HashSet<String> hashSet = new HashSet<String>(); hashSet.add("Rohan"); hashSet.add("Phil"); System.out.println("hashSet : " + hashSet + "\n"); ArrayList<String> arrayList = new ArrayList<String>(); arrayList.add("Ram"); arrayList.add("Dave"); arrayList.add("Peter"); System.out.println("arrayList : " + arrayList + "\n"); /* * Adds all of the elements in the arrayList to the hashSet. */ boolean isAdded = hashSet.addAll(arrayList); System.out.println("isAdded : " + isAdded); System.out.println("hashSet : " + hashSet + "\n"); } }
hashSet : [Rohan, Phil] arrayList : [Ram, Dave, Peter] isAdded : true hashSet : [Rohan, Dave, Phil, Peter, Ram]
https://sites.google.com/site/javaee4321/java-collections/HashSetDemoAddAll.zip?attredirects=0&d=1
See also:
No comments:
Post a Comment