返回两个集合的交集,而不修改原始集合。
//package com.nowjava; /* 来自 n o w j a v a . c o m*/ import java.util.HashSet; import java.util.Set; public class Main { /** * Returns the intersection of two sets without modifying the original sets.<p> * * @param <A> the type of objects contained in the sets * * @param first the first set * @param second the second set * * @return the intersection of both sets */ public static <A> Set<A> intersection(Set<A> first, Set<A> second) { HashSet<A> result =