Closed GoogleCodeExporter closed 8 years ago
You can do this with Sets.union(Sets.difference(a, b), Sets.difference(b, a)).
Note that this is a read-only, *live* view, which you may not have realized
(based on
your example code), so you might want to add .immutableCopy() to the end. Or you
could do it this way:
Set<A> xor = Sets.newHashSet();
xor.addAll(Sets.difference(a, b));
xor.addAll(Sets.difference(b, a));
I strongly suspect the need for this is too rare to justify a new method in the
library.
Original comment by kevin...@gmail.com
on 7 May 2009 at 6:24
(btw, the reason these approaches are preferable to the code you suggest is
that,
when the two sets have a large intersection, your code ends up producing an
overly-large, sparsely-populated hash set.)
Original comment by kevin...@gmail.com
on 7 May 2009 at 6:25
Original comment by kevin...@gmail.com
on 11 May 2009 at 5:08
Original issue reported on code.google.com by
harschw...@gmail.com
on 7 May 2009 at 6:10