how to check intersection of hashsets java code example Example: set intersection java set1.retainAll(set2);