There are two TreeSet
s in my app:
set1 = {501,502,503,504}
set2 = {502,503,504,505}
I want to get the symmetric difference of thes
You're after the symmetric difference. This is discussed in the Java tutorial.
Set symmetricDiff = new HashSet(set1);
symmetricDiff.addAll(set2);
// symmetricDiff now contains the union
Set tmp = new HashSet(set1);
tmp.retainAll(set2);
// tmp now contains the intersection
symmetricDiff.removeAll(tmp);
// union minus intersection equals symmetric-difference