Java Utililty Methods String Split by Delimiter

List of utility methods to do String Split by Delimiter

Description

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

Method

String[]split(String str, char delim)
Split a string on a delimiter.
List<String> strs;
int len;
int start, end;
if (str == null)
    return EMPTY_STRING_ARRAY;
if ((len = str.length()) == 0)
    return new String[] { "" };
strs = new ArrayList<String>(len);
...
String[]split(String str, char delimiter)
split
ArrayList elements = new ArrayList();
int i, j = 0, len = str.length();
for (i = 0; i < len; i++)
    if (str.charAt(i) == delimiter) {
        elements.add(str.substring(j, i));
        j = i + 1;
if (j < i)
...
ArrayListsplit(String str, char delimiter)
split
int prev = 0;
int len = str.length();
ArrayList<String> list = new ArrayList();
for (int i = 0; i < len; i++) {
    char c = str.charAt(i);
    if (c == delimiter) {
        if (i > prev)
            list.add(str.substring(prev, i));
...
String[]split(String str, char delimiter)
Split a string based on the given delimiter, but don't remove empty elements.
return split(str, delimiter, false);
Listsplit(String str, char delimiter)
A simple split method that uses String#substring(int,int) to split a string between a single character delimiter.
ArrayList<String> splitList = new ArrayList<>();
int from = 0, to = 0;
while (to >= 0) {
    to = str.indexOf(delimiter, from + 1);
    if (to < 0)
        splitList.add(str.substring(from));
    else
        splitList.add(str.substring(from, to));
...
Listsplit(String str, char delimiter)
Splits a string into substrings based on the supplied delimiter character.
if ((str == null) || "".equals(str)) {
    return new ArrayList();
ArrayList parts = new ArrayList();
int currentIndex;
int previousIndex = 0;
while ((currentIndex = str.indexOf(delimiter, previousIndex)) > 0) {
    String part = str.substring(previousIndex, currentIndex).trim();
...
String[]split(String str, char delimiter, boolean trim)
split
int s = 0;
int e = str.indexOf(delimiter, s);
if (e == -1) {
    if (trim) {
        str = str.trim();
    return new String[] { str };
List<String> ar = new ArrayList<String>();
do {
    String segment = str.substring(s, e);
    if (trim) {
        segment = segment.trim();
    ar.add(segment);
    s = e + 1;
    e = str.indexOf(delimiter, s);
} while (e != -1);
int len = str.length();
if (s < len) {
    String segment = str.substring(s);
    if (trim) {
        segment = segment.trim();
    ar.add(segment);
} else {
    ar.add("");
return ar.toArray(new String[ar.size()]);
String[]split(String str, int delim, String trailing)
Splits a string into substrings.
List<String> items = new ArrayList<String>(15);
int last = 0;
int index = 0;
int len = str.length();
while (index < len) {
    if (str.charAt(index) == delim) {
        items.add(str.substring(last, index));
        last = index + 1;
...
String[]split(String str, String delim)
Method that splits a string with delimited fields into an array of strings.
StringTokenizer strtok = new StringTokenizer(str, delim);
String[] result = new String[strtok.countTokens()];
for (int i = 0; i < result.length; i++) {
    result[i] = strtok.nextToken();
return result;
Listsplit(String str, String delim)
Split the given string str/code> delimited by given delimiter delim into string list.
List<String> splitList = null;
StringTokenizer st = null;
if (str == null) {
    return splitList;
if (isValid(delim)) {
    st = new StringTokenizer(str, delim);
} else {
...