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

ListsplitByStringSeparator(String theString, String separatorString)
This method tokenizes a given string using another given string as separator and returns a List containing found tokens.
List<String> tokenList = new ArrayList<String>();
if ((theString == null) || theString.equals("")) {
    return tokenList;
if (theString.equals(separatorString)) {
    return tokenList;
if ((separatorString == null) || separatorString.equals("")) {
...
double[]splitDoubles(String str, String fieldSeparator)
Convert a string of reals to a double array.
ArrayList array = new ArrayList();
StringTokenizer tokenizer = new StringTokenizer(str, fieldSeparator);
while (tokenizer.hasMoreTokens()) {
    array.add(tokenizer.nextToken());
double[] values = new double[array.size()];
for (int i = 0; i < values.length; i++) {
    try {
...
ListsplitField(String fieldWithSeparator, String separator)
Splits a multiple-value composed field into a list of String values
List<String> fieldsList = new ArrayList<String>();
if (fieldWithSeparator == null) {
    return fieldsList;
String[] fields = fieldWithSeparator.split(separator);
fieldsList = new ArrayList<String>(Arrays.asList(fields));
return fieldsList;
int[]splitInts(String string, String separator)
Split a string using the provided separator, then convert the split components to ints.
String[] split = string.trim().split(separator);
List<Integer> ints = new ArrayList<Integer>(split.length);
for (String s : split) {
    try {
        ints.add(Integer.valueOf(s.trim()));
    } catch (Exception e) {
int[] is = new int[ints.size()];
for (int i = 0; i < is.length; i++) {
    is[i] = ints.get(i);
return is;
ListsplitList(String source, char separator)
split List
return splitList(source, separator, false, null);
ListsplitListBySeparator(String text, String separator)
split List By Separator
String[] result = new String[] {};
if (text != null) {
    result = text.split(separator);
return new ArrayList<String>(Arrays.asList(result));
String[]splitNotRegex(String str, String separatorChars)
replace the method : String.split(String regex)
if (str == null) {
    return null;
int len = str.length();
if (len == 0) {
    return EMPTY_STRING_ARRAY;
int separatorLength = separatorChars.length();
...
ListsplitSmart(String s, char separator)
Split a string based on a separator, but don't split if it's inside a string.
ArrayList<String> lst = new ArrayList<String>(4);
int pos = 0, start = 0, end = s.length();
char inString = 0;
char ch = 0;
while (pos < end) {
    char prevChar = ch;
    ch = s.charAt(pos++);
    if (ch == '\\') { 
...
String[]splitStaySeparator(String str, char token)
split a String, if there are no character between two token this method place a empty String ( != String.split )
int i = str.indexOf(token);
int start = 0;
ArrayList<String> arrayList = new ArrayList<String>();
while (i >= 0) {
    arrayList.add(str.substring(start, i));
    start = i + 1;
    arrayList.add(str.substring(i, i + 1));
    i = str.indexOf(token, start);
...
ArrayListsplitString(String sInput, String sSeparator)
Splits a delimited String into a ArrayList of individual components example: ArrayList v = puakma.util.Util.splitString("NSW,VIC,QLD", ",");
if (sInput == null || sSeparator == null)
    return null;
ArrayList vReturn = new ArrayList();
int iPos = sInput.indexOf(sSeparator);
while (iPos >= 0) {
    String szToken = sInput.substring(0, iPos);
    sInput = sInput.substring(iPos + sSeparator.length(), sInput.length());
    vReturn.add(szToken);
...