Here you can find the source of intersectTwoSets(Set
private static <T> Set<T> intersectTwoSets(Set<T> a, Set<T> b)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { private static <T> Set<T> intersectTwoSets(Set<T> a, Set<T> b) { if (a == null || b == null) return new HashSet<>(); Set<T> result = new HashSet<>(a); result.retainAll(b);/*from w w w. j a va 2 s . c o m*/ return result; } }