How to convert a String into an ArrayList?

Try something like

List<String> myList = new ArrayList<String>(Arrays.asList(s.split(",")));
  • Arrays.asList documentation
  • String.split documentation
  • ArrayList(Collection) constructor documentation

Demo:

String s = "lorem,ipsum,dolor,sit,amet";

List<String> myList = new ArrayList<String>(Arrays.asList(s.split(",")));

System.out.println(myList);  // prints [lorem, ipsum, dolor, sit, amet]

This post has been rewritten as an article here.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)