In my String, I can have an arbitrary number of words which are comma separated. I wanted each word added into an ArrayList. E.g.:
String s = \"a,b,c,d,e,...
Try something like
List myList = new ArrayList(Arrays.asList(s.split(",")));
Demo:
String s = "lorem,ipsum,dolor,sit,amet";
List myList = new ArrayList(Arrays.asList(s.split(",")));
System.out.println(myList); // prints [lorem, ipsum, dolor, sit, amet]
This post has been rewritten as an article here.