Java String Tokenize extractTokens(String text, String delim)

Here you can find the source of extractTokens(String text, String delim)

Description

This method will extract tokens from a string containing multiple tokens and place the tokens in a collection.

License

BSD License

Parameter

Parameter Description
tokenCollection a parameter
tokenStr a parameter
delimeter a parameter

Declaration

public static List<String> extractTokens(String text, String delim) 

Method Source Code


//package com.java2s;
/*L//from w w  w .j a  va  2  s  .  co  m
 *  Copyright SAIC
 *
 *  Distributed under the OSI-approved BSD 3-Clause License.
 *  See http://ncip.github.com/stats-application-commons/LICENSE.txt for details.
 */

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**
     * This method will extract tokens from a string containing multiple tokens 
     * and place the tokens in a collection.  This is used for example, to parse strings containing multiple GO or PATHWAY ids.
     * @param tokenCollection
     * @param tokenStr
     * @param delimeter
     */
    public static List<String> extractTokens(String text, String delim) {
        List<String> tokenList = new ArrayList<String>();
        if (text != null) {
            String[] tokens = text.split(delim);

            for (int i = 0; i < tokens.length; i++) {
                tokenList.add(tokens[i].trim());
            }
        }
        return tokenList;
    }
}

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. getAllTokens(final String string)
  6. getCommandTokens(String commandString)
  7. getFileName(StringTokenizer s)
  8. getNameTokens(final String names)