Splits the string using a comma, creates and returns an array list of strings. - Java Collection Framework

Java examples for Collection Framework:Array Join

Description

Splits the string using a comma, creates and returns an array list of strings.

Demo Code


//package com.java2s;
import java.util.ArrayList;

public class Main {
    public static void main(String[] argv) throws Exception {
        String item = "java2s.com";
        System.out.println(split(item));
    }//from  w w w.  ja  v  a 2s  .c o  m

    /**
     * Splits the string using a comma, creates and returns an array list of strings.
     * @param item
     * @return
     */
    public static ArrayList<String> split(String item) {
        ArrayList<String> list = new ArrayList<String>();

        for (String i : item.split(","))
            list.add(i);

        return list;
    }
}

Related Tutorials