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

ListsplitToken(String str, String delimiter)
split Token
List<String> result = new ArrayList<String>();
int delimiterIndex = str.indexOf(delimiter);
if (delimiterIndex < 0) {
    result.add(str);
} else {
    result.add(str.substring(0, delimiterIndex));
    result.addAll(splitToken(str.substring(delimiterIndex + delimiter.length()), delimiter));
return result;
ListsplitToList(final String string, final String delim, final int limit)
split To List
int count = count(string, delim) + 1;
if (limit > 0 && count > limit) {
    count = limit;
final List<String> strings = new ArrayList<String>(count);
int begin = 0;
for (int i = 0; i < count; i++) {
    int end = string.indexOf(delim, begin);
...
ListsplitToList(String a_text, String a_delimiter)
Splits a line on a delimiter, removing any escape characters.
return splitToList(a_text, new String[] { a_delimiter });
ListsplitToList(String s, String delimRegEx)
split To List
List<String> l = new ArrayList<String>();
if (!isEmpty(s)) {
    if (isEmpty(delimRegEx)) {
        l.add(s);
    } else {
        String[] parts = s.split(delimRegEx);
        l = Arrays.asList(parts);
return l;
ListsplitToList(String str, char delimiter)
split To List
if (str == null || "".equals(str)) {
    return Collections.emptyList();
ArrayList<String> parts = new ArrayList<String>();
int currentIndex;
int previousIndex = 0;
while ((currentIndex = str.indexOf(delimiter, previousIndex)) > 0) {
    String part = str.substring(previousIndex, currentIndex).trim();
...
ListsplitUpTo(String s, String delimiter, int cnt)
Split up to a certain number of characters
List<String> toks = new ArrayList<String>();
for (int i = 0; i < cnt - 1; i++) {
    int idx = s.indexOf(delimiter);
    if (idx < 0) {
        break;
    toks.add(s.substring(0, idx));
    s = s.substring(idx + 1).trim();
...
String[]splitWhileKeepingParentheses(String value, char delimiter)
Splits the given String around the matches defined by the given delimiter into an array while not breaking up areas that are marked with parentheses ().
char[] valueChars = value.toCharArray();
int lastIndex = 0;
ArrayList strings = null;
boolean isParenthesesOpened = false;
for (int i = 0; i < valueChars.length; i++) {
    char c = valueChars[i];
    if (c == delimiter && !isParenthesesOpened) {
        if (strings == null) {
...
ListsplitWithEscapeChar(String s, char delimiter, char escape)
Split a string 's' using 'delimiter' but don't split on any delimiters escaped with 'escape' character.
String escapedDelimiter = String.format("\\%c\\%c", escape, delimiter);
final String sentinel = "~XYZ~";
String tmp = s.replaceAll(escapedDelimiter, sentinel);
String regex = String.format("\\%c", delimiter);
String[] tmpSplit = tmp.split(regex);
List<String> rv = new ArrayList<>(tmpSplit.length);
for (String myString : tmpSplit) {
    rv.add(myString.replaceAll(sentinel, "\\" + delimiter).trim());
...
String[]stringSplitter(String inStr, String delimiterStr)
string Splitter
ArrayList<String> stringVector = new ArrayList<String>();
String beforeStr;
while ((beforeStr = stringBefore(inStr, delimiterStr)) != null) {
    stringVector.add(beforeStr);
    inStr = stringAfter(inStr, delimiterStr);
stringVector.add(inStr);
return stringVector.toArray(new String[] {});
...
String[]tokenizerSplit(String string, String delimiter)
tokenizer Split
StringTokenizer token = new StringTokenizer(string, delimiter);
String[] array = new String[token.countTokens()];
int i = 0;
while (token.hasMoreTokens()) {
    array[i] = token.nextToken();
    i++;
return (array);
...