Java String Split splitOnTokens(String text)

Here you can find the source of splitOnTokens(String text)

Description

split On Tokens

License

Open Source License

Declaration

static String[] splitOnTokens(String text) 

Method Source Code


//package com.java2s;
import java.util.ArrayList;

public class Main {
    static String[] splitOnTokens(String text) {
        char[] array = text.toCharArray();
        if (text.indexOf("?") == -1 && text.indexOf("*") == -1) {
            return new String[] { text };
        }/*from  w w w.j  av  a2 s  . c  o  m*/

        ArrayList list = new ArrayList();
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < array.length; i++) {
            if (array[i] == '?' || array[i] == '*') {
                if (buffer.length() != 0) {
                    list.add(buffer.toString());
                    buffer.setLength(0);
                }
                list.add(new String(new char[] { array[i] }));
            } else {
                buffer.append(array[i]);
            }
        }
        if (buffer.length() != 0) {
            list.add(buffer.toString());
        }

        return (String[]) list.toArray(new String[0]);
    }
}

Related

  1. splitObjectString(String str)
  2. splitOgnl(String ognl)
  3. splitOn(String toSplit, String splitter)
  4. splitOnNoWiki(String s)
  5. splitOnTokens(String text)
  6. splitOrderedDurationsIntoIntervals(String[] durations, int numberOfIntervals)
  7. splitPackageName(String packageName)
  8. splitPackages(String packages)
  9. splitParagraphs(String value)