Android Utililty Methods String Split

List of utility methods to do String Split

Description

The list of methods to do String Split are organized into topic(s).

Method

String[]getStringArray(String str)
get String Array
String[] strarr = new String[1];
strarr[0] = str;
return strarr;
String[]split(String source, String separator, int arraylength)
split
String[] returnVal = new String[arraylength];
int cnt = 0;
int index0 = 0;
int index = source.indexOf(separator);
while (index >= 0 && cnt < (arraylength - 1)) {
    returnVal[cnt] = source.substring(index0, index);
    index0 = index + 1;
    index = source.indexOf(separator, index + 1);
...
String[]split(String str, String delims, boolean trimTokens)
This method is deprecated because it is too inflexible, providing only a very specific set of behaviors that almost never matches exactly what you intend.
StringTokenizer tokenizer = new StringTokenizer(str, delims);
int n = tokenizer.countTokens();
String[] list = new String[n];
for (int i = 0; i < n; i++) {
    if (trimTokens) {
        list[i] = tokenizer.nextToken().trim();
    } else {
        list[i] = tokenizer.nextToken();
...
ListstringToListStr(String input)
string To List Str
List<String> outList = new ArrayList<String>();
if (null == input || input.trim().isEmpty()) {
    return outList;
String[] out = input.split(COMMA);
return Arrays.asList(out);
ListsplitStringOnWhitespace(String stringToSplit)
split String On Whitespace
String[] array = stringToSplit.split("\\s+");
List<String> list = new ArrayList<String>();
for (int i = 0; i < array.length; i++) {
    list.add(array[i]);
return list;
ListstringToListByLine(final String fileContent)
string To List By Line
List<String> lineList = new LinkedList<String>();
for (String line : fileContent.split("\n")) {
    lineList.add(line);
return lineList;
String[]split(String str, String separatorChars)
split
return splitWorker(str, separatorChars, -1, false);
Listsplit(String str, char delimiter)
split
if (TextUtils.isEmpty(str)) {
    return Collections.emptyList();
int substringsCount = 1;
for (int i = 0, len = str.length(); i < len; i++) {
    if (str.charAt(i) == delimiter) {
        substringsCount++;
if (substringsCount == 1) {
    return Collections.singletonList(str);
List<String> split = new ArrayList<String>(substringsCount);
int index = str.indexOf(delimiter);
int lastIndex = 0;
while (index != -1) {
    split.add(str.substring(lastIndex, index));
    lastIndex = index + 1;
    index = str.indexOf(delimiter, lastIndex);
split.add(str.substring(lastIndex, str.length())); 
return split;
String[]split(String str, char separator)
split
return split(str, new String(new char[] { separator }));
String[]parseDelimitedList(String list, char delimiter)
Parse a list of substrings separated by a given delimiter.
String delim = "" + delimiter;
StringTokenizer st = new StringTokenizer(list + delim + " ", delim,
        true);
ArrayList<String> v = new ArrayList<String>();
String lastToken = "";
StringBuilder word = new StringBuilder();
while (st.hasMoreTokens()) {
    String tok = st.nextToken();
...