I have a String object like
final String demoString = "1,2,19,12";
Now I want to create a Collection<String> from it. How can I do that?
Guava:
List<String> it = Splitter.on(',').splitToList(demoString);
Standard JDK:
List<String> list = Arrays.asList(demoString.split(","))
Commons / Lang:
List<String> list = Arrays.asList(StringUtils.split(demoString, ","));
Note that you can't add or remove Elements from a List created by Arrays.asList, since the List is backed by the supplied array and arrays can't be resized. If you need to add or remove elements, you need to do this:
// This applies to all examples above
List<String> list = new ArrayList<String>(Arrays.asList( /*etc */ ))
Splitter.on(',').splitToList(demoString)