Java Utililty Methods String Tokenize

List of utility methods to do String Tokenize

Description

The list of methods to do String Tokenize are organized into topic(s).

Method

ListparseNMTokens(String nmTokens)
parse NM Tokens
StringTokenizer strTok = new StringTokenizer(nmTokens, " ");
List tokens = new Vector();
while (strTok.hasMoreTokens()) {
    tokens.add(strTok.nextToken());
return tokens;
String[]parseString(String in, String token)
Utility method to test equality on two possibly null objects
if (token == null)
    token = "\n";
StringTokenizer st = new StringTokenizer(in, token);
String[] ret = new String[st.countTokens()];
int i = 0;
while (st.hasMoreTokens())
    ret[i++] = st.nextToken();
return (ret);
...
ListreadTokens(String line)
Ritorna i tokens (separati dal carattere ';') di una stringa in una listsa di stringhe
int nTokens = 1;
for (int i = 0; i < line.length(); i++) {
    if (line.charAt(i) == ';')
        nTokens++;
List<String> tokens = new ArrayList<String>();
int i = 0;
for (int j = 1; j < line.length(); j++) {
...
String[]removeEmptyStrings(String[] tokens)
remove Empty Strings
ArrayList<String> result = new ArrayList<>();
for (String token : tokens)
    if (!token.equals(""))
        result.add(token);
String[] res = new String[result.size()];
result.toArray(res);
return res;
String[]removeMatchingRegex(String regex, String replacement, String[] tokens, boolean removeEmpty)
Applies given regex on tokens and may optionally delete when a token gets empty.
String[] tk = new String[tokens.length];
for (int i = 0; i < tokens.length; i++) {
    tk[i] = tokens[i].replaceAll(regex, replacement);
if (removeEmpty) {
    tk = removeEmpty(tk);
return tk;
...
String[]removeStopWords(String[] tokens, Set stopWords)
remove Stop Words
List<String> res = new ArrayList<String>();
for (String token : tokens) {
    if (!stopWords.contains(token))
        res.add(token);
return res.toArray(new String[0]);
ListstringTokenizer(String in)
z Convert string to array
List<String> l = new ArrayList<>();
for (int i = 0; i < in.length(); i++) {
    l.add(in.substring(i, i + 1));
return l;
ListsubstringsBetween(final String str, final String open, final String close, boolean tokenReservedFlag)

Searches a String for substrings delimited by a start and end tag, returning all matching substrings in an array.

A null input String returns null .

if (str == null || isEmpty(open) || isEmpty(close)) {
    return null;
final int strLen = str.length();
if (strLen == 0) {
    return new ArrayList<>();
final int closeLen = close.length();
...
String[]tokenArray(StringTokenizer st)
token Array
int l = st.countTokens();
String[] r = new String[l];
for (int i = 0; i < l; i++) {
    r[i] = st.nextToken();
return r;
String[]tokenize(final String aInput, final String aDelimiters)
Tokenizes a given input stream and breaks it into parts on the given delimiters.
if (aInput == null) {
    return null;
final List<String> result = new ArrayList<String>();
final StringTokenizer tokenizer = new StringTokenizer(aInput, aDelimiters, false );
while (tokenizer.hasMoreTokens()) {
    String token = tokenizer.nextToken();
    result.add(token.trim());
...