Java String Split by Char splitFast3(String data, char splitChar)

Here you can find the source of splitFast3(String data, char splitChar)

Description

split Fast

License

Apache License

Declaration

public static String[] splitFast3(String data, char splitChar) 

Method Source Code

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

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static String[] splitFast3(String data, char splitChar) {

        if (data == null) {
            return new String[0];
        }//from w  ww  . j  av  a  2s. c om

        List<String> result = new ArrayList<String>();
        int last = 0;
        int dataLength = data.length();
        for (int i = 0; i < dataLength; i++) {
            if (data.charAt(i) == splitChar) {
                result.add(data.substring(last, i));
                last = i + 1;
            }
        }

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

    public static String substring(String src, String fromToken, String toToken) {
        int from = src.indexOf(fromToken);
        if (from == -1)
            return null;
        from += fromToken.length();
        int to = src.indexOf(toToken, from);
        if (to == -1) {
            return src.substring(from);
        }
        return src.substring(from, to);
    }

    public static int indexOf(String nextLine, char c) {
        int length = nextLine.length();
        for (int i = 0; i < length; i++) {
            if (c == nextLine.charAt(i))
                return i;
        }
        return -1;
    }

    public static int indexOf(String nextLine, char[] chars) {
        int length = nextLine.length();
        for (int i = 0; i < length; i++) {
            for (char c : chars) {
                if (c == nextLine.charAt(i))
                    return i;
            }
        }

        return -1;
    }
}

Related

  1. splitAt(String str, char c)
  2. splitByChar(final String message, final char ch)
  3. splitByNonNestedChars(String s, char... c)
  4. splitChars(String input, String charsToBeRemoved)
  5. splitEncolosed(String s, char open_tag, char close_tag)
  6. splitInclusive(CharSequence input, char[] splitChars)
  7. splitList(String source, char useChar)
  8. splitOnChar(String str, char c)
  9. splitOnChar(String str, int ch)