Java: How to convert String[] to List or Set [duplicate]
Solution 1:
Arrays.asList() would do the trick here.
String[] words = {"ace", "boom", "crew", "dog", "eon"};
List<String> wordList = Arrays.asList(words);
For converting to Set, you can do as below
Set<T> mySet = new HashSet<T>(Arrays.asList(words));
Solution 2:
The easiest way would be:
String[] myArray = ...;
List<String> strs = Arrays.asList(myArray);
using the handy Arrays utility class. Note, that you can even do
List<String> strs = Arrays.asList("a", "b", "c");