You are on page 1of 3

Nama : Mohammad Wahyu Ardiansyah

Kelas :TIF E

NIM : 205150201111058

package PBO;

import java.util.*;

import java.util.HashSet;

public class Collection {

public static Set Union(Set x, Set y){

Set union = new TreeSet(x);

union.addAll(y);

return union;

public static Set Intersection(Set x, Set y){

Set intersection = new TreeSet(x);

intersection.retainAll(y);

return intersection;

public static Set Difference(Set a, Set b){

TreeSet difference = new TreeSet(a);

difference.removeAll(b);

return difference;
}

public static boolean Disjoint(Set a, Set c){

Set disjoint = new TreeSet(a);

disjoint.retainAll(c);

if(disjoint.size() == 0){

return true;

}else {

return false;

public static void main(String[] args) {

Set a = new HashSet();

a.add(1);

a.add(2);

Set y = new HashSet();

b.add(2);

b..add(3);

Set c = new HashSet();

c.add(1);

c.add(2);

c.add(3);

Set d = new HashSet();

d.add(3);

d.add(5);
Set e = new HashSet();

e.add(4);

e.add(5);

System.out.println(Collection.Union(a,b));

System.out.println(Collection.Intersection(a,b));

System.out.println(Collection.Difference(c,d));

System.out.println(Collection.Disjoint(a,e));

You might also like