SetUtils { public static <T> Set<T> symmetricDifference(Set<? extends T> s1, Set<? extends T> s2) { Set<T> s3 = new HashSet<>() ; s1.forEach(x -> { if ( !s2.contains(x) ) s3.add(x) ; }) ; s2.forEach(x -> { if ( !s1.contains(x) ) s3.add(x) ; }) ; return s3 ; } private  SetUtils(); static final Set<X> concurrentHashSet(); static Set<T> intersection(Set<? extends T> setLeft, Set<? extends T> setRight); static boolean intersectionP(Set<? extends T> s1, Set<? extends T> s2); static Set<T> union(Set<? extends T> s1, Set<? extends T> s2); static Set<T> symmetricDifference(Set<? extends T> s1, Set<? extends T> s2); static Set<T> difference(Set<? extends T> s1, Set<? extends T> s2); static Set<T> toSet(Stream<T> stream);  }
@Test public void set_symmetric_differnce_1() { Set<Integer> x1 = set(1,2,3) ; Set<Integer> x2 = set(4,3) ; Set<Integer> expected = set(4,1,2) ; assertEquals(expected, SetUtils.symmetricDifference(x1, x2)) ; }
@Test public void set_symmetric_differnce_3() { Set<Integer> x1 = set(1,2,3) ; Set<Integer> x2 = set(2,3,1) ; Set<Integer> expected = set() ; assertEquals(expected, SetUtils.symmetricDifference(x1, x2)) ; }
@Test public void set_symmetric_differnce_4() { Set<Integer> x1 = set(1,2,3) ; Set<Integer> x2 = set() ; Set<Integer> expected = set(1,2,3) ; assertEquals(expected, SetUtils.symmetricDifference(x1, x2)) ; assertEquals(expected, SetUtils.symmetricDifference(x2, x1)) ; }