Java String Tokenize tokenize(final String aInput, final String aDelimiters)

Here you can find the source of tokenize(final String aInput, final String aDelimiters)

Description

Tokenizes a given input stream and breaks it into parts on the given delimiters.

License

Open Source License

Parameter

Parameter Description
aInput the input string to tokenize, can be <code>null</code>;
aDelimiters the delimiter <em>characters</em> to break the given input on, cannot be <code>null</code>.

Return

the individual tokens of the given input, or null if the original input was null.

Declaration

public static String[] tokenize(final String aInput, final String aDelimiters) 

Method Source Code


//package com.java2s;
/*/*  w  w w  . j  a v a  2  s  .co  m*/
 * OpenBench LogicSniffer / SUMP project 
 *
 * 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.,
 * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
 *
 * 
 * Copyright (C) 2010-2011 J.W. Janssen, www.lxtreme.nl
 */

import java.util.*;

public class Main {
    /**
     * Tokenizes a given input stream and breaks it into parts on the given
     * delimiters.
     * 
     * @param aInput
     *          the input string to tokenize, can be <code>null</code>;
     * @param aDelimiters
     *          the delimiter <em>characters</em> to break the given input on,
     *          cannot be <code>null</code>.
     * @return the individual tokens of the given input, or <code>null</code> if
     *         the original input was <code>null</code>.
     */
    public static String[] tokenize(final String aInput, final String aDelimiters) {
        if (aInput == null) {
            return null;
        }

        final List<String> result = new ArrayList<String>();

        final StringTokenizer tokenizer = new StringTokenizer(aInput, aDelimiters, false /* returnDelims */);
        while (tokenizer.hasMoreTokens()) {
            String token = tokenizer.nextToken();
            result.add(token.trim());
        }

        return result.toArray(new String[result.size()]);
    }
}

Related

  1. removeMatchingRegex(String regex, String replacement, String[] tokens, boolean removeEmpty)
  2. removeStopWords(String[] tokens, Set stopWords)
  3. stringTokenizer(String in)
  4. substringsBetween(final String str, final String open, final String close, boolean tokenReservedFlag)
  5. tokenArray(StringTokenizer st)
  6. tokenize(final String s)
  7. tokenize(String array, String delimiter)
  8. tokenize(String formula)
  9. tokenize(String in)