我想实例化一组集合(字符串),然后放置两个 Set<String>
进入它,如下所示:
Set<String> setOne = retrieveSetOne();
Set<String> setTwo = retrieveSetTwo();
Set<Set<String>> myCollection = new HashSet<new HashSet<String<()>(); // not working
myCollection.add(setOne);
myCollection.add(setTwo);
问题是,我的嵌套集实例化不起作用。我该怎么做?
最佳答案
更改为
Set<Set<String>> myCollection = new HashSet<Set<String>>();
创建实例时通过实现进行初始化,对于需要匹配声明的类型,
如果您已经使用 Java7,那么您可以简单地使用
Set<Set<String>> myCollection = new HashSet<>();
关于java - 在Java中实例化集合的集合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25212946/