Java 两个集合取交集

public static Set intersectionSet(Set setA, Set setB) {
Set intersectionSet = new HashSet();
Iterator iterA = setA.iterator();
while (iterA.hasNext()) {
Object tempInner = iterA.next();
if (setB.contains(tempInner)) {
intersectionSet.add(tempInner);
}
}
return intersectionSet;
}

你可能感兴趣的:(java)