Java String Tokenize tokenize(String text, String delimiter)

Here you can find the source of tokenize(String text, String delimiter)

Description

tokenize

License

LGPL

Declaration

public static List<String> tokenize(String text, String delimiter) 

Method Source Code

//package com.java2s;
/**//from w  ww.ja  va2s.c om
 * The Clican-Pluto software suit is Copyright 2009, Clican Company
 * and individual contributors, and is licensed under the GNU LGPL.
 *
 * @author clican
 *
 */

import java.util.ArrayList;

import java.util.List;

public class Main {

    public static List<String> tokenize(String text, String delimiter) {
        if (delimiter == null) {
            throw new RuntimeException("delimiter is null");
        }
        if (text == null) {
            return new ArrayList<String>();
        }

        List<String> pieces = new ArrayList<String>();

        int start = 0;
        int end = text.indexOf(delimiter);
        while (end != -1) {
            pieces.add(text.substring(start, end));
            start = end + delimiter.length();
            end = text.indexOf(delimiter, start);
        }

        if (start < text.length()) {
            pieces.add(text.substring(start));
        }

        return pieces;
    }
}

Related

  1. tokenize(String text)
  2. tokenize(String text)
  3. tokenize(String text)
  4. tokenize(String text, char separator)
  5. tokenize(String text, char separator)
  6. tokenize(String value)
  7. tokenize(String value)
  8. tokenize(String[] stringArray, String delimiter)
  9. tokenizeAutocomplete(String text, int minSize)