Java String Tokenize getTokens(String string)

Here you can find the source of getTokens(String string)

Description

Parse a string into tokens where whitespace is the delimiter.

License

Open Source License

Parameter

Parameter Description
string The string to parse.

Return

The array of tokens.

Declaration

static protected String[] getTokens(String string) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    /**//from  ww w  .  j  av  a2  s.  c o m
     * Parse a string into tokens where whitespace is the delimiter.
     * @param string The string to parse.
     * @return The array of tokens.
     */
    static protected String[] getTokens(String string) {
        return getTokens(string, " \t");
    }

    /**
     * Parse a string into tokens with the specified delimiter.
     * @param string The string to parse.
     * @param delim The delimiter
     * @return The array of tokens.
     */
    static protected String[] getTokens(String string, String delim) {
        StringTokenizer tokenizer = new StringTokenizer(string, delim);
        int numTokens = tokenizer.countTokens();
        String[] tokens = new String[numTokens];

        for (int index = 0; index < numTokens; index++) {
            tokens[index] = tokenizer.nextToken();
        }

        return tokens;
    }
}

Related

  1. getTokens(final String s)
  2. getTokens(String msg, String delim)
  3. getTokens(String str, String delim)
  4. getTokens(String str, String delimiter)
  5. getTokens(String string)
  6. getTokens(String string, String tokenSeparator)
  7. getTokens(String value)
  8. getTokens(String vbt)
  9. getTokenTypes(CommonTree tree)