我有这个输入:
Set<List<String>> allSafe = new HashSet<>();
Set<List<String>> allErrors = new HashSet<>();
我如何基于allSafe过滤allErrors的元素?例如,如果我有:
allErrors = [["h","k"],["hi","ho","ha"]]
allSafe = [["h","k"],["sh","ho","ii","oo"],["h","zzz"]]
那么预期的输出应该是:filteredAllSafe = [["sh","ii","oo"],["zzz"]]
这是我的尝试,但未按预期工作:返回空列表集:
public static Set<List<String>> filterSafe(
Set<List< String >> allSafe, Set<List< String >> allErrors) {
Set<List<String>> filteredSet =
safePath.stream().filter(s -> s.contains(allErrors)).collect(Collectors.toSet());
return filteredSet;
}
这将起作用: