Remove one set from another set
import java.util.HashSet;
import java.util.Set;
public class Main {
public static void main(String[] args) {
Set<Integer> uniques = new HashSet<Integer>();
Set<Integer> dups = new HashSet<Integer>();
uniques.add(new Integer(1));
uniques.add(new Integer(2));
uniques.add(new Integer(3));
uniques.add(new Integer(4));
dups.add(new Integer(1));
dups.add(new Integer(2));
dups.add(new Integer(3));
uniques.removeAll(dups);
System.out.println("Unique words: " + uniques);
System.out.println("Duplicate words: " + dups);
}
}
Output:
Unique words: [4]
Duplicate words: [1, 2, 3]
Home
Java Book
Runnable examples
Java Book
Runnable examples
Collection Set:
- Convert set to an Array
- Convert Set into List
- Convert a set to a synchronized Set
- Is a particular value in(exist) Set
- Iterator a set
- Maximum element of Set
- Minimum element of a Set
- Remove all elements from a set
- Remove element from Set
- Remove one set from another set
- Remove all the elements from one set to another set
- Union(Add) all the elements from one set to another set
- Intersection of one set and another set
- Set operations: union, intersection, difference
- Set operations: symmetric difference, is subset, is superset
- Size of a Set