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