Java String Tokenize getTokens(String str, String delimiter)

Here you can find the source of getTokens(String str, String delimiter)

Description

Return the tokens in a string in a list.

License

Apache License

Parameter

Parameter Description
str String to be tokenized
delimiter Characters which are delimit tokens

Return

List of string tokens contained in the tokenized string

Declaration

public static List<String> getTokens(String str, String delimiter) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    /**/*from w ww . ja  v a2 s .  co  m*/
     * Return the tokens in a string in a list. This is particularly
     * helpful if the tokens need to be processed in reverse order. In that case,
     * a list iterator can be acquired from the list for reverse order traversal.
     *
     * @param str String to be tokenized
     * @param delimiter Characters which are delimit tokens
     * @return List of string tokens contained in the tokenized string
     */
    public static List<String> getTokens(String str, String delimiter) {
        ArrayList<String> l = new ArrayList<String>();
        StringTokenizer tokens = new StringTokenizer(str, delimiter);
        while (tokens.hasMoreTokens()) {
            l.add(tokens.nextToken());
        }
        return l;
    }
}

Related

  1. getStringTokens(String str)
  2. getTokenArray(String sequence, String[] chain, boolean paired, boolean includeDelim)
  3. getTokens(final String s)
  4. getTokens(String msg, String delim)
  5. getTokens(String str, String delim)
  6. getTokens(String string)
  7. getTokens(String string)
  8. getTokens(String string, String tokenSeparator)
  9. getTokens(String value)