在Java中将数据从HashSet移动到ArrayList

Gha*_*eer 16 java list arraylist hashset data-structures

Set在Java中有以下内容:

Set< Set<String> > SetTemp = new HashSet< Set<String> >();
Run Code Online (Sandbox Code Playgroud)

我想将其数据移动到ArrayList:

ArrayList< ArrayList< String > > List = new ArrayList< ArrayList< String > >);
Run Code Online (Sandbox Code Playgroud)

有可能吗?

abh*_*sia 47

将数据移动HashSetArrayList

Set<String> userAllSet = new HashSet<String>(usrAllTemp);
List<String> usrAll = new ArrayList<String>(userAllSet);
Run Code Online (Sandbox Code Playgroud)

usrAllTemp是一个ArrayList有一些价值的东西.usrAll(ArrayList)获得价值的同样方式userAllSet(HashSet).


ass*_*ias 13

你只需要循环:

Set<Set<String>> setTemp = new HashSet<Set<String>> ();
List<List<String>> list = new ArrayList<List<String>> ();
for (Set<String> subset : setTemp) {
    list.add(new ArrayList<String> (subset));
}
Run Code Online (Sandbox Code Playgroud)

注意:您应该以小型大写字母启动变量名称以遵循Java约定.