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 src, char separator, boolean trim)
split
List<String> result = new ArrayList<String>();
for (int i1 = 0; i1 < src.length();) {
    int i2 = src.indexOf(separator, i1);
    if (i2 < 0)
        i2 = src.length();
    String item = src.substring(i1, i2);
    if (trim)
        item = item.trim();
...
String[]split(String str, char separator)
split
if (str.isEmpty()) {
    return new String[] { "" };
ArrayList<String> strList = new ArrayList<>();
int startIndex = 0;
int nextIndex = 0;
while ((nextIndex = str.indexOf(separator, startIndex)) != -1) {
    strList.add(str.substring(startIndex, nextIndex));
...
String[]split(String str, char separator)
we can't use String.split as it is a JDK 1.4 method.
int pos = 0;
List list = new ArrayList();
int length = str.length();
for (int i = 0; i < length; i++) {
    char ch = str.charAt(i);
    if (ch == separator) {
        list.add(str.substring(pos, i));
        pos = i + 1;
...
String[]split(String str, char separator)
split
if (str == null)
    return null;
if (str.length() == 0)
    return new String[0];
List splitList = new ArrayList();
int startPos = 0;
int endPos = str.indexOf(separator);
while (endPos != -1) {
...
String[]split(String str, char separator)
split
return split(str, separator, false, -1, -1, false);
String[]split(String str, char separatorChar)

Splits the provided text into an array, separator specified.

if (str == null) {
    return EMPTY_STRING_ARRAY.clone();
int len = str.length();
if (len == 0) {
    return EMPTY_STRING_ARRAY.clone();
List<String> list = new ArrayList<String>();
...
String[]split(String str, char separatorChar)
split
if (str == null) {
    return null;
int length = str.length();
if (length == 0) {
    return EMPTY_STRINGS;
List<String> list = new ArrayList();
...
String[]split(String str, char separatorChar)

Splits the provided text into an array, separator specified.

if (str == null) {
    return null;
int len = str.length();
if (len == 0) {
    return EMPTY_STRING_ARRAY;
List list = new ArrayList();
...
Listsplit(String str, char separatorChar)

Splits the provided text into an array, separator specified.

List<String> list = new ArrayList<String>();
if (str == null || str.length() == 0) {
    return list;
if (str.indexOf(separatorChar) == -1) {
    list.add(str);
    return list;
int start = 0;
for (int i = 0; i < str.length(); i++) {
    if (str.charAt(i) == separatorChar) {
        String token = str.substring(start, i).trim();
        if (token.length() > 0) {
            list.add(token);
        start = i + 1;
String token = str.substring(start, str.length()).trim();
if (token.length() > 0) {
    list.add(token);
return list;
String[]split(String str, char separatorChar)
split
if (str == null) {
    return null;
int length = str.length();
if (length == 0) {
    return new String[0];
List<String> list = new ArrayList<String>();
...