Java String Tokenize tokenize(String text, char separator)

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

Description

tokenize

License

Open Source License

Declaration

public static List<String> tokenize(String text, char separator) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004-2010 Sunil Kamath (IcemanK).
 * All rights reserved./*from ww w. j  a va  2s  .  c  om*/
 * This program is made available under the terms of the Common Public License
 * v1.0 which is available at http://www.eclipse.org/legal/cpl-v10.html
 *
 * Contributors:
 *     Sunil Kamath (IcemanK) - initial API and implementation
 *******************************************************************************/

import java.util.*;

public class Main {
    public static List<String> tokenize(String text, char separator) {
        List<String> list = new ArrayList<String>();
        if (text != null && text.length() > 0) {
            char[] chars = text.toCharArray();
            StringBuffer buf = new StringBuffer(""); //$NON-NLS-1$
            for (int i = 0; i < chars.length; i++) {
                if (chars[i] != separator) {
                    buf.append(chars[i]);
                } else {
                    list.add(buf.toString());
                    buf.delete(0, buf.length());
                }
            }
            list.add(buf.toString().trim());
        }
        return list;
    }
}

Related

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