Java String Tokenize tokens(String exp)

Here you can find the source of tokens(String exp)

Description

tokens

License

LGPL

Declaration

public static ArrayList<String> tokens(String exp) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.util.ArrayList;

public class Main {
    public static ArrayList<String> tokens(String exp) {
        ArrayList<String> array = new ArrayList<String>();
        String subexp = "";
        int numPar = 0;
        int start = 0;
        boolean open = false;
        for (int i = 0; i < exp.length(); i++) {
            if (exp.charAt(i) == '(') {
                open = true;/* w  w  w .ja  v  a 2s. c  om*/
                if (numPar == 0)
                    start = i;
                numPar++;
            } else if (exp.charAt(i) == ')') {
                numPar--;
            }
            if (numPar == 0 && open) {
                open = false;
                subexp = exp.substring(start, i + 1);
                array.add(subexp);
            }
        }
        return array;
    }
}

Related

  1. tokenizeToStringArray(String str, String delimiters)
  2. tokenizeToStringArray(String str, String delimiters)
  3. tokenizeToStringArray(String str, String delimiters)
  4. tokenizeToStringArray(String str, String seperators)
  5. tokenizeWhitespace(String input)
  6. toStringToArray(String str, String token)
  7. toTokens(String s)
  8. unpackConllSentenceToTokens(String input)