Here you can find the source of commaDelimitedListToStringArray(String str)
Parameter | Description |
---|---|
str | a parameter |
public static String[] commaDelimitedListToStringArray(String str)
//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()]); } }