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, String delim)
Returns a list of tokens delimited by delim in String str.
if (str == null || delim == null) {
    throw new NullPointerException("Cannot pass null arguments to tokenize");
if (delim.length() == 0) {
    throw new IllegalArgumentException("Delimiter can not be zero length");
List<Integer> l = new ArrayList<Integer>();
int nextStartIndex = 0;
...
Listsplit(String str, String delim)
Returns a list of substrings created by splitting the given string at the given delimiter.
if (str == null)
    return null;
ArrayList<String> list = new ArrayList<String>();
if (delim == null) {
    list.add(str);
    return list;
int subStart, afterDelim = 0;
...
String[]split(String str, String delim)
Splits the given string into chunks.
int startOffset = 0;
int endOffset = -1;
int sepLength = delim.length();
List lines = new ArrayList(15);
while ((endOffset = str.indexOf(delim, startOffset)) > -1) {
    lines.add(str.substring(startOffset, endOffset));
    startOffset = endOffset + sepLength;
if (startOffset > 0) {
    lines.add(str.substring(startOffset));
} else {
    lines.add(str);
return (String[]) lines.toArray(EMPTY_STRING_ARRAY);
String[]split(String str, String delim)
Splits a string containing n occurrences of delim into n+1 strings that don't contain delim (and whose occurrences in str are bounded by delim).
List<String> lines = new ArrayList<String>();
int startPos = 0;
while (true) {
    int endPos = indexOf(str, delim, startPos);
    if (endPos == -1) {
        if (startPos > 0 || startPos < str.length()) {
            lines.add(str.substring(startPos));
        break;
    lines.add(str.substring(startPos, endPos));
    startPos = endPos + delim.length();
    String[] result = new String[lines.size()];
    int i = 0;
    for (String line : lines) {
        result[i] = line;
        i++;
    return result;
Stringsplit(String str, String delimeter)
split
List<String> subStrList = new ArrayList<String>();
StringBuilder buf = new StringBuilder();
for (int i = 0; i < str.length(); i++) {
    if (Character.isUpperCase(str.charAt(i))) {
        subStrList.add(buf.toString());
        buf.setLength(0);
    buf.append(str.charAt(i));
...
String[]split(String str, String delimiter)
Splits "string" by "Delimiter"
List<String> strings = new ArrayList<String>();
int start = 0;
int len = str.length();
int dlen = delimiter.length();
int offset = str.lastIndexOf(delimiter); 
if (dlen < 1)
    return null;
else if (offset < 0) 
...
Listsplit(String str, String delimiter)
split
List<String> result = new ArrayList<>();
if (delimiter.isEmpty()) {
    throw new IllegalArgumentException("Empty delimiter!");
int position = 0;
while (position < str.length()) {
    int old = position;
    int pos = str.indexOf(delimiter, position);
...
ArrayListsplit(String str, String delimiter)
Splits a String using indexOf instead of regex to speed things up.
return split(str, delimiter, 10);
String[]split(String str, String delimiter)
split
ArrayList list = new ArrayList();
int idx = 0;
while (true) {
    idx = str.indexOf(delimiter);
    if (idx == -1) {
        list.add(str);
        break;
    list.add(str.substring(0, idx));
    str = str.substring(idx + delimiter.length());
return (String[]) list.toArray(new String[list.size()]);
String[]split(String str, String delimiter)
split
String[] strs = str.split(delimiter);
ArrayList<String> list = new ArrayList<String>(strs.length);
for (String s : strs) {
    if (s != null && (s = s.trim()).length() > 0) {
        list.add(s);
return list.toArray(new String[0]);
...