Java: Is there an easy, quick way to AND, OR, or XOR together sets?
问题 That is, if I had two or more sets, and I wanted to return a new set containing either: All of the elements each set has in common (AND). All of the elements total of each set (OR). All of the elements unique to each set. (XOR). Is there an easy, pre-existing way to do that? Edit: That's the wrong terminology, isn't it? 回答1: 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