Working with collections, sometimes you need to get an actual array that contains the list. Sometimes in Java array should be converted to List. Check it out how to...
This example code converts an array to a list:
List listOfStrings = Arrays.asList(arrayOfStrings);
On the fly list construction:
List listOfStrings = Arrays.asList(new String[]{s1, s2});
And how to convert a list into an array:
String[] arrayOfStrings = listOfStrings.toArray(new String[]{});
or
String[] arrayOfStrings = listOfStrings.toArray(new String[0]);
This example code converts an array to a list:
List
On the fly list construction:
List
And how to convert a list into an array:
String[] arrayOfStrings = listOfStrings.toArray(new String[]{});
or
String[] arrayOfStrings = listOfStrings.toArray(new String[0]);