diff --git a/hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java b/hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java index c3ae49c56..07a2e0d55 100644 --- a/hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java @@ -326,6 +326,39 @@ public class CollUtil { return result; } + /** + * 计算集合的单差集,即只返回【集合1】中有,但是【集合2】中没有的元素,例如: + * + *
+	 *     subtractToList([1,2,3,4],[2,3,4,5]) -》 [1]
+	 * 
+ * + * @param coll1 集合1 + * @param coll2 集合2 + * @param 元素类型 + * @return 单差集 + * @since 5.3.5 + */ + public static List subtractToList(Collection coll1, Collection coll2) { + + if (isEmpty(coll1)) { + return ListUtil.empty(); + } + if (isEmpty(coll2)) { + return ListUtil.list(true, coll2); + } + + //将被交数用链表储存,防止因为频繁扩容影响性能 + final List result = new LinkedList<>(); + Set set = new HashSet<>(coll2); + for (T t : coll1) { + if (false == set.contains(t)) { + result.add(t); + } + } + return result; + } + /** * 判断指定集合是否包含指定值,如果集合为空(null或者空),返回{@code false},否则找到元素返回{@code true} * diff --git a/hutool-http/src/main/java/cn/hutool/http/server/action/RootAction.java b/hutool-http/src/main/java/cn/hutool/http/server/action/RootAction.java index d7e8836f8..9b4c66803 100644 --- a/hutool-http/src/main/java/cn/hutool/http/server/action/RootAction.java +++ b/hutool-http/src/main/java/cn/hutool/http/server/action/RootAction.java @@ -54,6 +54,8 @@ public class RootAction implements Action { response.write(file); } } + } else{ + response.write(file); } }