/**
* Splits a string into tokens, separated by the given delimiter. The
* delimiter is not included in the resulting list, nor is it part of any of
* the resulting tokens.
*
* @param input
* The string to split.
* @param delimiter
* The character used to separate tokens in the input string.
* @param wantEmptyTokens
* true if consecutive delimiters must generate
* empty tokens; false to output only tokens of
* length 1 or more.
* @return List of tokens found within the input string.
*/
public static List split(final String input, final char delimiter, final boolean wantEmptyTokens) {
final ArrayList result = new ArrayList();
int curChar = 0;
int nextChar = input.indexOf(delimiter, curChar);
while (nextChar != -1) {
if (input.charAt(curChar) != delimiter)
result.add(input.substring(curChar, nextChar));
else if (wantEmptyTokens)
result.add("");
curChar = nextChar;
curChar++;
nextChar = input.indexOf(delimiter, curChar);
}
if (curChar == input.length()) {
// A delimiter ends the input.
if (wantEmptyTokens)
result.add("");
} else
// Add the last token.
result.add(input.substring(curChar));
return result;
}