There are many other reasons for wanting to convert a String to a List. For example, the length of the String needs to be defined. Such a restriction does not exist in an ArrayList.
import java.util.*;
public class StringToList {
public static void main(String[] args) {
// initialize string array
String[] w = {"convert", "string", "to", "list"};
// convert to string array to list
List<String> myList = Arrays.asList(w);
// add to ArrayList
ArrayList al = new ArrayList(myList);
// print the list contents
System.out.println(al.toString());
}
}
Arrays.asList() is the function which actually converts String to List. The remainder of the code is show a working example.