String to arraylist in java

Java convert string to arraylist java example

package com.w3schools;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class StringToArrayList {
  public static void main(String args[]){
	try {
		String namesString = "Jai,Mahesh,Vivek,Naren,Vishal,Hemant";
                String str[] = namesString.split(",");
        
                List strList = new ArrayList();
                strList = Arrays.asList(str);
                for(String string : strList){
                   System.out.println(string);
                }
	} catch (Exception e) {
		e.printStackTrace();
	}
  }
}

Output:

Jai
Mahesh
Vivek
Naren
Vishal
Hemant

Download this example.