Java String Split by Delimiter splitFast(String text, char delim)

Here you can find the source of splitFast(String text, char delim)

Description

split Fast

License

Open Source License

Declaration

public static List<String> splitFast(String text, char delim) 

Method Source Code


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

public class Main {
    static final char NL_CODE = '\n';

    public static List<String> splitFast(String text, char delim) {
        List<String> result = new ArrayList<String>();
        String s = text;//  ww w.  j  av a 2  s  .  co  m
        while (!s.isEmpty()) {
            int pos = s.indexOf(delim);
            if (pos == -1) {
                result.add(s);
                break;
            } else {
                result.add(s.substring(0, pos));
            }
            s = s.substring(pos + 1);
        }
        return result;
    }

    public static List<String> splitFast(String s) {
        if (s != null) {
            List<String> list = splitFast(s, NL_CODE);
            return list;
        } else {
            return new ArrayList<String>(0);
        }
    }
}

Related

  1. splitAndTrim(String string, String delim)
  2. SplitAt(String s, String delimiter)
  3. SplitAt(String str, String delimiter)
  4. splitByStr(String s, String delim)
  5. splitChars(String str, String delimiters)
  6. splitForChar(final String string, final char delimiter)
  7. splitHtmlTagKeepDelimiter(String tag, String input)
  8. splitKeepDelimiter(String delimiter, String input)
  9. splitList(String data, String delims)