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