That is, if I had two or more sets, and I wanted to return a new set containing either:
Is there an easy, pre-existing way to do that?
Edit: That's the wrong terminology, isn't it?
Assuming 2 Set objects a and b
AND(intersection of two sets)
a.retainAll(b);
OR(union of two sets)
a.addAll(b);
XOR either roll your own loop:
foreach item
if(a.contains(item) and !b.contains(item) || (!a.contains(item) and b.contains(item)))
c.add(item)
or do this:
c.addAll(a);
c.addAll(b);
a.retainAll(b); //a now has the intersection of a and b
c.removeAll(a);
See the Set documentation and this page. For more.