Java String Tokenize getAllTokens(final String string)

Here you can find the source of getAllTokens(final String string)

Description

Applies StringTokenizer to the string and returns all the tokens found.

License

Open Source License

Parameter

Parameter Description
string the string to tokenize.

Return

all the tokens found in string.

Declaration

public static String[] getAllTokens(final String string) 

Method Source Code


//package com.java2s;
import java.util.*;

public class Main {
    /**//from w  w w.j a  v  a  2 s  . c  o m
     * Separator string for lists.
     */
    public static final String LIST_SEPARATOR = ",";

    /**
     * Applies StringTokenizer to the string and returns all the tokens found.
     *
     * @param string the string to tokenize.
     * @return all the tokens found in string.
     */
    public static String[] getAllTokens(final String string) {
        return getAllTokens(string, LIST_SEPARATOR);
    }

    /**
     * Applies StringTokenizer to the string and returns all the tokens found.
     *
     * @param string    the string to tokenize.
     * @param separator the separator for the tokens.
     * @return all the tokens found in string.
     */
    public static String[] getAllTokens(final String string, final String separator) {
        final StringTokenizer tokenizer = new StringTokenizer(string, separator);
        final String[] tokens = new String[tokenizer.countTokens()];
        for (int i = 0; i < tokens.length; ++i)
            tokens[i] = tokenizer.nextToken().trim();
        return tokens;
    }
}

Related

  1. conservativeTokenize(String text)
  2. countCommonTokens(String string1, String string2)
  3. escapedTokens(String s, char separator)
  4. extractTokens(String strStartToken, String strEndToken, String strExpression)
  5. extractTokens(String text, String delim)
  6. getCommandTokens(String commandString)
  7. getFileName(StringTokenizer s)
  8. getNameTokens(final String names)
  9. getParamFloat(StringTokenizer s)