Moving data from a HashSet to ArrayList in Java

房东的猫 提交于 2019-12-03 11:14:51

You simply need to loop:

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));
}

Note: you should start variable names in small caps to follow Java conventions.

abhishek ringsia

Moving Data HashSet to ArrayList

Set<String> userAllSet = new HashSet<String>(usrAllTemp);
List<String> usrAll = new ArrayList<String>(userAllSet);

Here usrAllTemp is an ArrayList, which has some values. Same Way usrAll(ArrayList) getting values from userAllSet(HashSet).

You can use addAll():

Set<String> gamesInstalledTemp = new HashSet< Set<String> >();
List<String> gamesInstalled = new ArrayList<>();
gamesInstalled.addAll(gamesInstalledTemp);

You can use the Stream and collector to do this, I hope it is the easiest way

listname = setName.stream().collect(Collectors.toList());
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!