Java 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[]split(String s)
split
List<String> result = new ArrayList<>();
int counter = 0;
while (counter <= s.length()) {
    int pos = s.indexOf(",", counter);
    if (pos == -1) {
        pos = s.length();
    String fragment = s.substring(counter, pos);
...
Listsplit(String s)
Splits on whitespace (\\s+).
return (split(s, "\\s+"));
Listsplit(String s)
Splits on whitespace (\\s+).
return split(s, "\\s+");
String[]split(String s)
Split input into substrings on the assumption that it is either only one string or it was generated using List.toString(), with tokens
SPLIT_START {string} { SPLIT_DELIM {string}} SPLIT_END
 (e.g., "[one, two, three]"). 
if (null == s) {
    return null;
if ((!s.startsWith(SPLIT_START)) || (!s.endsWith(SPLIT_END))) {
    return new String[] { s };
s = s.substring(SPLIT_START.length(), s.length() - SPLIT_END.length());
final int LEN = s.length();
...
Listsplit(String s)
Splits on whitespace (\\s+).
return (split(s, "\\s+"));
String[]split(String s, int c)
Split a string using the char code of a character.
List<String> list = new ArrayList<String>();
if (s != null) {
    int pos = 0, end;
    while ((end = s.indexOf(c, pos)) >= 0) {
        String sub = s.substring(pos, end);
        list.add(sub);
        pos = end + 1;
    list.add(s.substring(pos));
if (list.isEmpty()) {
    return null;
int size = list.size();
if (list.get(size - 1).isEmpty()) {
    size--;
String[] result = new String[size];
for (int i = 0; i < size; i++) {
    result[i] = list.get(i);
return result;
String[]split(String s, String at)
split
List<String> result = new ArrayList<String>();
int i, last = 0;
while ((i = s.indexOf(at, last)) != -1) {
    result.add(s.substring(last, i));
    last = i + at.length();
result.add(s.substring(last));
return result.toArray(new String[0]);
...
String[]split(String s, String s1)
split
StringTokenizer stringtokenizer = new StringTokenizer(s1, s);
String as[] = new String[stringtokenizer.countTokens()];
int i = 0;
while (stringtokenizer.hasMoreTokens()) {
    as[i++] = stringtokenizer.nextToken();
return as;
String[]split(String s, String seperator)
custom string splitting function as CDC/Foundation does not include String.split();
if (s == null || seperator == null || s.length() == 0 || seperator.length() == 0) {
    return (new String[0]);
List tokens = new ArrayList();
String token;
int index_a = 0;
int index_b = 0;
while (true) {
...
String[]split(String s, String spliter, boolean removeEmptyItem)
split
String[] arr = (s == null) ? new String[0] : s.split(spliter);
if (removeEmptyItem) {
    ArrayList<String> temp = new ArrayList<>();
    for (int i = 0; i < arr.length; i++) {
        if (!"".equals(arr[i].trim())) {
            temp.add(arr[i].trim());
    arr = temp.toArray(new String[0]);
return arr;