intersect two sets of objects in java code example Example: set intersection java set1.retainAll(set2);