Android String Split split(String str, String delimiter)

Here you can find the source of split(String str, String delimiter)

Description

same as the String.split(), except it doesn't use regexes, so it's faster.

Parameter

Parameter Description
str - the string to split up
delimiter the delimiter

Return

the split string

Declaration

public static String[] split(String str, String delimiter) 

Method Source Code

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

public class Main {
    /**/* ww  w .jav a 2s .  com*/
     * same as the String.split(), except it doesn't use regexes, so it's faster.
     *
     * @param str       - the string to split up
     * @param delimiter the delimiter
     * @return the split string
     */
    public static String[] split(String str, String delimiter) {
        List<String> result = new ArrayList<String>();
        int lastIndex = 0;
        int index = str.indexOf(delimiter);
        while (index != -1) {
            result.add(str.substring(lastIndex, index));
            lastIndex = index + delimiter.length();
            index = str.indexOf(delimiter, index + delimiter.length());
        }
        result.add(str.substring(lastIndex, str.length()));

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

Related

  1. split(String original, String separator)
  2. split(String original, String separator)
  3. split(String s, String sep)
  4. split(String source, String separator)
  5. split(String str, String delim)
  6. split(String str, String delims)
  7. split(String str, String separator)
  8. split(final String str, final String delim)
  9. splitDirString(String dirSection)