Java String Tokenize tokenizeToStringArray(String str, String delimiters)

Here you can find the source of tokenizeToStringArray(String str, String delimiters)

Description

tokenize To String Array

License

Open Source License

Parameter

Parameter Description
str a parameter
delimiters a parameter

Return

String[]

Declaration

public static String[] tokenizeToStringArray(String str, String delimiters) 

Method Source Code

//package com.java2s;

import java.util.*;

public class Main {
    /**//from w w w. j av a  2s.com
     *
     * @param str
     * @param delimiters
     * @return String[]
     */
    public static String[] tokenizeToStringArray(String str, String delimiters) {
        return tokenizeToStringArray(str, delimiters, true, true);
    }

    /**
     *
     * @param str
     * @param delimiters
     * @param trimTokens
     * @param ignoreEmptyTokens
     * @return String[]
     */
    public static String[] tokenizeToStringArray(String str, String delimiters, boolean trimTokens,
            boolean ignoreEmptyTokens) {

        StringTokenizer st = new StringTokenizer(str, delimiters);
        List tokens = new ArrayList();
        while (st.hasMoreTokens()) {
            String token = st.nextToken();
            if (trimTokens) {
                token = token.trim();
            }
            if (!ignoreEmptyTokens || token.length() > 0) {
                tokens.add(token);
            }
        }
        return (String[]) tokens.toArray(new String[tokens.size()]);
    }
}

Related

  1. tokenizeString(String inString, char delimiter, String enclosures)
  2. tokenizeStringArray(String[] array, String token)
  3. tokenizeStringWithQuotes(String line, String quoteStyle)
  4. tokenizeToStringArray(String str, String delimiters)
  5. tokenizeToStringArray(String str, String delimiters)
  6. tokenizeToStringArray(String str, String seperators)
  7. tokenizeWhitespace(String input)
  8. tokens(String exp)
  9. toStringToArray(String str, String token)