Organizational Research By

Surprising Reserch Topic

how to convert a Set<String> to a List<String> in java collection

I am currently doing this:

Set<String> listOfTopicAuthors = ....

List<String> list = Arrays.asList( 
    listOfTopicAuthors.toArray( new String[0] ) );

Can you beat this ?

asked Jun 22, 2015 in Core java by rahulgii
0 votes

Related Hot Questions

2 Answers

0 votes
List list = new ArrayList(listOfTopicAuthors);
answered Jun 22, 2015 by rahulgii
0 votes

Try this for Set,

Set<String> listOfTopicAuthors=.....
List<String> setList=new ArrayList<String>(listOfTopicAuthors); 

Try this for Map,

 Map<String, String> listOfTopicAuthors=.....
// List of values:
    List<String> mapValueList=new ArrayList<String>(listOfTopicAuthors.values());
// List of keys:
    List<String> mapKeyList=new ArrayList<String>(listOfTopicAuthors.KeySet());
answered Jun 22, 2015 by rahulgii