Click here to watch in Youtube :
https://www.youtube.com/watch?v=qTu4tIVVILg&list=UUhwKlOVR041tngjerWxVccw
LinkedHashSetExample.java
Output
https://www.youtube.com/watch?v=qTu4tIVVILg&list=UUhwKlOVR041tngjerWxVccw
LinkedHashSetExample.java
import java.util.ArrayList; import java.util.LinkedHashSet; /* * Example of removeAll(Collection<? extends E> c) method. */ public class LinkedHashSetExample { public static void main( String[] args ) { LinkedHashSet<String> linkedHashSet = new LinkedHashSet<String>(); linkedHashSet.add("Rohan"); linkedHashSet.add("Phil"); linkedHashSet.add("Ram"); linkedHashSet.add("Dave"); linkedHashSet.add("Peter"); System.out.println("linkedHashSet : " + linkedHashSet + "\n"); ArrayList<String> arrayList = new ArrayList<String>(); arrayList.add("Ram"); arrayList.add("Dave"); arrayList.add("Peter"); System.out.println("arrayList : " + arrayList + "\n"); /* * Removes from this set all of its elements that are contained in the * specified collection. */ boolean isRemoved = linkedHashSet.removeAll(arrayList); System.out.println("isRemoved : " + isRemoved); System.out.println("linkedHashSet : " + linkedHashSet + "\n"); } }
linkedHashSet : [Rohan, Phil, Ram, Dave, Peter] arrayList : [Ram, Dave, Peter] isRemoved : true linkedHashSet : [Rohan, Phil]
https://sites.google.com/site/javaee4321/java-collections/LinkedHashSetDemoRemoveAll.zip?attredirects=0&d=1
See also:
No comments:
Post a Comment