Looly 5 年 前
コミット
7a1438fc02

+ 4 - 1
hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java

@@ -278,6 +278,7 @@ public class CollUtil {
 	 * @param coll2      集合2
 	 * @param coll2      集合2
 	 * @param otherColls 其它集合
 	 * @param otherColls 其它集合
 	 * @return 并集的集合,返回 {@link LinkedHashSet}
 	 * @return 并集的集合,返回 {@link LinkedHashSet}
+	 * @since 5.3.9
 	 */
 	 */
 	@SafeVarargs
 	@SafeVarargs
 	public static <T> Set<T> intersectionDistinct(Collection<T> coll1, Collection<T> coll2, Collection<T>... otherColls) {
 	public static <T> Set<T> intersectionDistinct(Collection<T> coll1, Collection<T> coll2, Collection<T>... otherColls) {
@@ -294,7 +295,9 @@ public class CollUtil {
 
 
 		if (ArrayUtil.isNotEmpty(otherColls)) {
 		if (ArrayUtil.isNotEmpty(otherColls)) {
 			for (Collection<T> otherColl : otherColls) {
 			for (Collection<T> otherColl : otherColls) {
-				result.retainAll(otherColl);
+				if(isNotEmpty(otherColl)){
+					result.retainAll(otherColl);
+				}
 			}
 			}
 		}
 		}
 		return result;
 		return result;

+ 1 - 1
hutool-core/src/test/java/cn/hutool/core/collection/CollUtilTest.java

@@ -81,7 +81,7 @@ public class CollUtilTest {
 	}
 	}
 	
 	
 	@Test
 	@Test
-	public void intersectionTest2() {
+	public void intersectionDistinctTest() {
 		ArrayList<String> list1 = CollUtil.newArrayList("a", "b", "b", "c", "d", "x");
 		ArrayList<String> list1 = CollUtil.newArrayList("a", "b", "b", "c", "d", "x");
 		ArrayList<String> list2 = CollUtil.newArrayList("a", "b", "b", "b", "c", "d");
 		ArrayList<String> list2 = CollUtil.newArrayList("a", "b", "b", "b", "c", "d");
 		ArrayList<String> list3 = CollUtil.newArrayList();
 		ArrayList<String> list3 = CollUtil.newArrayList();