How to calculate the intersection of two sets?
Use the retainAll() method of Set: If you want to preserve the sets, create a new set to hold the intersection: The javadoc of retainAll() says it’s exactly what you want: Retains only the elements in this set that are contained in the specified collection (optional operation). In other words, removes from this set all of its elements that are not contained in the … Read more