Java Utililty Methods String Split by Separator

List of utility methods to do String Split by Separator

Description

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

Method

Listsplit(String s, char separator)
split
int i = s.indexOf(separator);
List<String> list = new ArrayList<>();
if (i < 0) {
    list.add(s);
    return list;
for (; i >= 0 && i < s.length();) {
    String sub = s.substring(0, i).trim();
...
Listsplit(String s, char separator)
split
if (s == null || s.length() == 0)
    return Collections.emptyList();
List<String> list = new ArrayList<>();
int i, pos = 0;
while ((i = s.indexOf(separator, pos)) >= 0) {
    if (i > pos)
        list.add(s.substring(pos, i));
    pos = i + 1;
...
String[]split(String s, char separator)
split
if (s == null)
    return null;
ArrayList<String> parts = new ArrayList<String>();
int beginIndex = 0, endIndex;
while ((endIndex = s.indexOf(separator, beginIndex)) >= 0) {
    parts.add(s.substring(beginIndex, endIndex));
    beginIndex = endIndex + 1;
parts.add(s.substring(beginIndex));
String[] a = new String[parts.size()];
return parts.toArray(a);
String[]split(String s, char separator)
split
if (s == null)
    return null;
ArrayList<String> parts = new ArrayList<String>();
int beginIndex = 0, endIndex;
while ((endIndex = s.indexOf(separator, beginIndex)) >= 0) {
    parts.add(s.substring(beginIndex, endIndex));
    beginIndex = endIndex + 1;
parts.add(s.substring(beginIndex));
String[] a = new String[parts.size()];
return parts.toArray(a);
String[]split(String s, char separator)
Devuelve una cadena troceada.
Vector v = new Vector();
for (int ini = 0, end = 0; ini < s.length(); ini = end + 1) {
    end = s.indexOf(separator, ini);
    if (end == -1)
        end = s.length();
    String st = s.substring(ini, end);
    if (st.length() > 0)
        v.addElement(st);
...
String[]split(String s, String separator)
Mimics the the Java SE String#split(String) method.
int separatorlen = separator.length();
ArrayList tokenList = new ArrayList();
String tmpString = "" + s;
int pos = tmpString.indexOf(separator);
while (pos >= 0) {
    String token = tmpString.substring(0, pos);
    tokenList.add(token);
    tmpString = tmpString.substring(pos + separatorlen);
...
Listsplit(String s, String separator)
split
List<String> result = new ArrayList<>();
int lastIndex = 0;
int index = s.indexOf(separator);
while (index != -1) {
    String substring = s.substring(lastIndex, index);
    if (!substring.equals(separator) && index > 0)
        result.add(substring);
    lastIndex = index + separator.length();
...
Listsplit(String s, String separator)
Splits string by separator, if separator in string is backslashed, i.e.
if (s == null)
    return null;
List<String> rslt = null;
if (s.isEmpty() || isEmpty(separator)) {
    rslt = new ArrayList<>(1);
    rslt.add(s);
    return rslt;
int start = 0;
int p = start;
do {
    int j = s.indexOf(separator, p);
    if (j == -1) {
        if (rslt == null) {
            rslt = new ArrayList<>(1);
            rslt.add(s);
            return rslt;
        rslt.add(s.substring(start));
        break;
    if (j > 0 && s.charAt(j - 1) == '\\') {
        p = j + 1;
        continue;
    } else {
        if (rslt == null)
            rslt = new ArrayList<String>();
        rslt.add(s.substring(start, j));
        start = j + 1;
        p = start;
} while (true);
return rslt;
String[]split(String s, String separator)
Splits a string.
int sepLength = separator.length();
if (sepLength == 0)
    return new String[] { s };
ArrayList<String> tokens = new ArrayList<>();
int length = s.length();
int start = 0;
do {
    int p = s.indexOf(separator, start);
...
Listsplit(String src, char separator)
split
List<String> ret = new ArrayList<String>();
int p = 0;
while (0 <= (p = src.indexOf(separator))) {
    ret.add(src.substring(0, p));
    src = src.substring(p + 1);
ret.add(src);
return ret;
...