Remove one set from another set : HashSet « Collections Data Structure « Java
- Java
- Collections Data Structure
- HashSet
Remove one set from another set
import java.util.HashSet;
import java.util.Set;
public class FindDups2 {
public static void main(String[] args) {
Set<String> uniques = new HashSet<String>();
Set<String> dups = new HashSet<String>();
for (String a : args)
if (!uniques.add(a))
dups.add(a);
uniques.removeAll(dups);
System.out.println("Unique words: " + uniques);
System.out.println("Duplicate words: " + dups);
}
}
Related examples in the same category