Sets methods in Java

Lets discuss some methods commonly used with Sets in java

 Set<String> diff2 = new HashSet<>(SetA);
 diff2.removeAll(SetB);

But instead there is a workaround. Create a union of two Sets using addAll.And then create a Set that only contains common elements and then remove common elements from the union.

     Set<String> unionTest = new HashSet<>(SetA);
     unionTest.addAll(SetB);

     System.out.println("===========Intersection================");
     Set<String> intersectionTest  = new HashSet<>(SetA);
     intersectionTest.retainAll(SetB);

     System.out.println("===========symmetric diff================");
     unionTest.removeAll(intersectionTest);