converts a given comma separated String into a list of Strings - Java java.lang

Java examples for java.lang:Math Convert

Description

converts a given comma separated String into a list of Strings

Demo Code

/**/*from   w  ww. ja v a  2  s .c  o  m*/
 * Project: richContentMediaSearchService
 * ROLE-Project
 * authors: daniel.dahrendorf@im-c.de, julian.weber@im-c.de
 * This software uses the GNU GPL   
 */
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import org.apache.log4j.Logger;

public class Main{
    public static void main(String[] argv) throws Exception{
        String inputString = "java2s.com";
        System.out.println(convertToList(inputString));
    }
    /**
     * converts a given comma separated String into a list of Strings
     * @param inputString
     * @return
     */
    public static List<String> convertToList(String inputString) {
        ArrayList<String> list = new ArrayList<String>();
        if (inputString == null || inputString.equals("")) {
            return list;
        }

        String[] strings = inputString.split(",");
        for (String s : strings) {
            list.add(s);
        }
        return list;
    }
}

Related Tutorials