假设Streams和Collections,Lambdas可以使用吗?我尝试使用 for 循环,但它没有解决我的问题。
// Set<Set<String>> to Set<String>
for(Set<String> s : set) {
    result.addAll(s);
    set.add(result);
}
set 是一种Set<Set<String>>类型, result 是Set<String>.
这是使用 Stream API 的选项:
Set<String> result = sets.stream()
    .flatMap(Collection::stream)
    .collect(Collectors.toSet());