mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
fix bug
This commit is contained in:
parent
1abab026dd
commit
76a47b3c54
@ -326,6 +326,39 @@ public class CollUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算集合的单差集,即只返回【集合1】中有,但是【集合2】中没有的元素,例如:
|
||||
*
|
||||
* <pre>
|
||||
* subtractToList([1,2,3,4],[2,3,4,5]) -》 [1]
|
||||
* </pre>
|
||||
*
|
||||
* @param coll1 集合1
|
||||
* @param coll2 集合2
|
||||
* @param <T> 元素类型
|
||||
* @return 单差集
|
||||
* @since 5.3.5
|
||||
*/
|
||||
public static <T> List<T> subtractToList(Collection<T> coll1, Collection<T> coll2) {
|
||||
|
||||
if (isEmpty(coll1)) {
|
||||
return ListUtil.empty();
|
||||
}
|
||||
if (isEmpty(coll2)) {
|
||||
return ListUtil.list(true, coll2);
|
||||
}
|
||||
|
||||
//将被交数用链表储存,防止因为频繁扩容影响性能
|
||||
final List<T> result = new LinkedList<>();
|
||||
Set<T> set = new HashSet<>(coll2);
|
||||
for (T t : coll1) {
|
||||
if (false == set.contains(t)) {
|
||||
result.add(t);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断指定集合是否包含指定值,如果集合为空(null或者空),返回{@code false},否则找到元素返回{@code true}
|
||||
*
|
||||
|
@ -54,6 +54,8 @@ public class RootAction implements Action {
|
||||
response.write(file);
|
||||
}
|
||||
}
|
||||
} else{
|
||||
response.write(file);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user