Split string to Array by delimiter - Android java.lang

Android examples for java.lang:String Split

Description

Split string to Array by delimiter

Demo Code

import java.util.StringTokenizer;

public class Main{

    /**//from w  w  w .  j a v  a2 s .co m
     * 
     * @param original
     * @return
     */
    public static String[] toArray(String original, String delimiter) {
        if (original == null || original.length() == 0) {
            return null;
        }
        StringTokenizer st = new StringTokenizer(original, delimiter);
        String[] kws = new String[st.countTokens()];
        int i = 0;
        while (st.hasMoreTokens()) {
            String s = st.nextToken();
            kws[i++] = s;
        }
        return kws;
    }

}

Related Tutorials