Java String Tokenize tokenize(String input)

Here you can find the source of tokenize(String input)

Description

Take the given string and chop it up into a series of strings on whitespace boundries.

License

Open Source License

Declaration

public static String[] tokenize(String input) 

Method Source Code

//package com.java2s;
/*// ww w  .j a  v a 2 s.  c o m
 * @(#)Utilities.java   1.2 30.01.2003
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

import java.util.*;

public class Main {
    /**
     * Take the given string and chop it up into a series
     * of strings on whitespace boundries.  This is useful
     * for trying to get an array of strings out of the
     * resource file.
     */
    public static String[] tokenize(String input) {
        return tokenize(input, " \t\n\r\f");
    }

    public static String[] tokenize(String input, String delim) {
        if (input == null)
            return new String[] {};
        StringTokenizer t = new StringTokenizer(input, delim);
        String cmd[];

        cmd = new String[t.countTokens()];
        int i = 0;
        while (t.hasMoreTokens()) {
            cmd[i] = (String) t.nextToken();
            i++;
        }

        return cmd;
    }
}

Related

  1. tokenize(String array, String delimiter)
  2. tokenize(String formula)
  3. tokenize(String in)
  4. tokenize(String input)
  5. tokenize(String input)
  6. tokenize(String input, char by)
  7. tokenize(String input, String delim)
  8. tokenize(String line)
  9. tokenize(String s)