我有以下代码:
Object value = methodOutOfMyControl();
Collection<LinkedHashSet<String>> values = ((Map) value).values();
Set<String> strings = new HashSet<String>();
for (LinkedHashSet<String> set : values) {
strings.addAll(set);
}
有没有办法更简洁地重写此代码?
P.S.我使用java 6
最佳答案
这看起来更好:
Collection<LinkedHashSet<String>> values = ((Map) userPreferenceValue).values();
Set<String> contraValues = Sets.newHashSet(Iterables.concat(values));
关于java - 将多个集合合并为一个集合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34923378/