Java Comma Separated List commaDelimitedListToStringArray(String str)

Here you can find the source of commaDelimitedListToStringArray(String str)

Description

comma Delimited List To String Array

License

Open Source License

Parameter

Parameter Description
str a parameter

Return

String[]

Declaration

public static String[] commaDelimitedListToStringArray(String str) 

Method Source Code

//package com.java2s;

import java.util.*;

public class Main {
    /**/* ww  w.j  a  v a 2s. co  m*/
     *
     * @param str
     * @return String[]
     */
    public static String[] commaDelimitedListToStringArray(String str) {
        return delimitedListToStringArray(str, ",");
    }

    /**
     *
     * @param str
     * @param delimiter
     * @return String[]
     */
    public static String[] delimitedListToStringArray(String str, String delimiter) {
        if (str == null) {
            return new String[0];
        }
        if (delimiter == null) {
            return new String[] { str };
        }

        List result = new ArrayList();
        int pos = 0;
        int delPos = 0;
        while ((delPos = str.indexOf(delimiter, pos)) != -1) {
            result.add(str.substring(pos, delPos));
            pos = delPos + delimiter.length();
        }
        if (str.length() > 0 && pos <= str.length()) {
            result.add(str.substring(pos));
        }

        return (String[]) result.toArray(new String[result.size()]);
    }
}

Related

  1. addJvmArgumentsAndOptions(final List commandLine, final String[] jvmArgsOpts)
  2. addMultiLine(String multiLine, List commandsList)
  3. addPropertyToCommand(List command, String key, String value)
  4. commaDelimitedListToStringArray(final String str)
  5. commaDelimitedListToStringArray(String str)
  6. commaDelimitedListToStringArray(String str)
  7. commaDelimitedListToStringArray(String str)
  8. commaDelimitedStringToList(String str)
  9. commaDelimitedToList(String commaDelimited)